#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;}} else{ int md=a; map mp; if(c%b==0||c%a==0){ printf("%d\n",c); return 0; } for(int i=b;i-b<=c;i+=b){ int tmp=i+(c-i+a-1)/a*a; //printf("%d %d\n",i,tmp); if(tmp%a){ if(mp[tmp%a]){ans=mp[md];break;} else{mp[tmp%a]=tmp;md=min(tmp%a,md);} } else{ printf("%d\n",ans=tmp); return 0; } } ans=mp[md]; } printf("%d\n",ans); return 0; }