ax +by=c,c=gcd*t,
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<set>
#include<string.h>
#include<vector>
#include<deque>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
ll t;
int gcd(int a,int b)
{
if(b==0)return a;
return gcd(b,a%b);
}
inline ll exgcd(ll a,ll b,ll &x,ll &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
ll d=exgcd(b,a%b,y,x);
y-=(a/b)*x;
return d;
}
inline ll sol(ll a,ll p)
{
ll x,y;
ll d=exgcd(a,p,x,y);
x=x*t/d;
ll f=p/d;
return (x%f+f)%f;
}
int main(){
IOS;
ll a,b;
while(cin>>a>>b>>t)
{
cout<<sol(a,b)<<endl;
}
return 0;
}