#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #pragma warning(disable:4996) //#define ATCODER #ifdef ATCODER #include #endif typedef long long ll; typedef unsigned long long ull; #define LINF 9223300000000000000 #define LINF2 1223300000000000000 #define LINF3 1000000000000 #define INF 2140000000 //const long long MOD = 1000000007; const long long MOD = 998244353; using namespace std; #ifdef ATCODER using namespace atcoder; #endif void solve() { int a, b, c; scanf("%d%d%d", &a, &b, &c); vector v(c, INF); int i, j; for (i = 0; i < c; i++) { for (j = 0; j < c; j++) { int tmp = i * a + j * b; v[tmp%c] = min(v[tmp%c], tmp/c); } } int ans = 0; for (i = 0; i < c; i++) { if (v[i] == INF) { printf("INF\n"); return; } ans += v[i]; } printf("%d\n", ans); return; } int main() { #if 1 solve(); #else int T, t; cin >> T; for (t = 0; t < T; t++) { //cout << "Case #" << t + 1 << ": "; solve(); } #endif return 0; }