#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #include <utility> #include <functional> #include <stack> #include <array> #include <list> #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair<int, int> P; int main() { int a, b, c; cin>>a>>b>>c; if(gcd(gcd(a, b), c)>1){ cout<<"INF"<<endl; return 0; } if(c<a) swap(c, a); if(c<b) swap(c, b); const int INF=1e9+7; int d[2020]; fill(d, d+c, INF); d[0]=0; deque<int> deq; deq.push_back(0); while(!deq.empty()){ int x=deq[0]; deq.pop_front(); if(x+a>=c){ if(d[x+a-c]>d[x]+1){ deq.push_back(x+a-c); d[x+a-c]=d[x]+1; } }else{ if(d[x+a]>d[x]){ deq.push_front(x+a); d[x+a]=d[x]; } } if(x+b>=c){ if(d[x+b-c]>d[x]+1){ deq.push_back(x+b-c); d[x+b-c]=d[x]+1; } }else{ if(d[x+b]>d[x]){ deq.push_front(x+b); d[x+b]=d[x]; } } } int ans=0; for(int i=0; i<c; i++){ ans+=d[i]; } cout<<ans<<endl; return 0; }