P1516 青蛙的约会

数论题,找找规律搞一搞就行了

 1 // luogu-judger-enable-o2
 2 #include
 3 #include
 4 #include
 5 //#include<>
 6 using namespace std;
 7 
 8 long long ans,x1,y1,x,y,m,n,l,a,b;
 9 
10 long long ab(long long la){
11     return la>0?la:-la;
12 }
13 
14 int exgcd(long long a,long long b,long long &x1,long long &y1){
15     if(!b){
16         x1=1;
17         y1=0;
18         return a;
19     }
20     ans=exgcd(b,a%b,x1,y1);
21     long long t=x1;
22     x1=y1;
23     y1=t-a/b*y1;
24     return ans;
25 }
26 
27 int main(){
28     scanf("%lld%lld%lld%lld%lld",&x,&y,&m,&n,&l);
29     a=x-y;
30     b=n-m;
31     if(b<0){
32         b=-b;
33         a=-a;
34     }
35     exgcd(b,l,x1,y1);
36     if(a%ans){
37         printf("Impossible\n");
38     }
39     else{
40         printf("%lld\n",((x1*(a/ans))%(l/ans)+(l/ans))%(l/ans));
41     }
42     return 0;
43 }

 

你可能感兴趣的:(P1516 青蛙的约会)