0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 16:16:25 +00:00
https://sjzezoj.com/submission/14145
This commit is contained in:
Baoshuo Ren 2021-07-13 17:03:51 +08:00 committed by Baoshuo Ren
parent d788a4cf5e
commit 6d72585647
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

40
S2OJ/480/480.cpp Normal file
View File

@ -0,0 +1,40 @@
#include <bits/stdc++.h>
using namespace std;
long long n, m, t, ans, x;
long long gcd(long long a, long long b) {
if (!b) return a;
return gcd(b, a % b);
}
int main() {
cin >> n >> m >> t;
if (!m) {
cout << -1 << endl;
exit(0);
}
if (!n) {
cout << 0 << endl;
exit(0);
}
x = gcd(n, m);
n /= x;
m /= x;
while (n != 1 || m != 1) {
if (n < m) swap(n, m);
ans += n / m;
n %= m;
if (!n) {
n += m;
ans--;
}
if (n < 1 || m < 1) {
cout << -1 << endl;
exit(0);
}
}
cout << ++ans * t << endl;
return 0;
}