#include #include #include #include using namespace std; int main(){ int a,b,c;scanf("%d%d%d",&a,&b,&c); long long cm=(long long)a*b;if(a>b)swap(a,b); int ans=2*1000000000; if(cm>c){ for(int i=0;i-b<=c;i+=b){ int tmp=i+(c-i+a-1)/a*a;if(ans>tmp)ans=tmp; } printf("%d\n",ans);return 0; } int n=a,m=b; int x=0;while(x=m%n){m=n;n=x;};//cm/=n; printf("%d\n",(int)((c+cm-1)/cm)); return 0; int md=a; map mp; if(c%b==0||c%a==0){ printf("%d\n",c);return 0; } for(int i=0;i-b<=c;i+=b){ int tmp=i+(c-i+a-1)/a*a; int mc=(c-i);mc%=a;//if(mc<0)mc=-mc; if(mc){ if(mp[mc]){ans=mp[md];printf("%d\n",ans);return 0;} else{mp[mc]=tmp;md=min(mc,md);} } else{ printf("%d\n",ans=tmp); return 0; } } printf("%d\n",mp[md]); return 0; }