1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| #include <cstdio> #define ll long long using namespace std; ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b); } void exgcd(ll a,ll b,ll& x,ll& y){ if(b==0){ x=1,y=0; return; } exgcd(b,a%b,x,y); ll temp=x; x=y; y=temp-a/b*y; return; } int main() { ll a,b,c,m,n,x,y,l,t,k,ans; while(scanf("%lld%lld%lld%lld%lld",&x,&y,&m,&n,&l)!=EOF){ a=n-m; b=l; c=x-y; t=gcd(a,b); if(c%t!=0){ printf("Pat\n"); } else{ a/=t; b/=t; c/=t; exgcd(a,b,x,y); if(b<0){ b=-b; } x=((x*c)%b+b)%b; if(x<0){ x+=b; } printf("%lld\n",x); } } return 0; }
|