标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 106959 | Accepted: 21291 |
Description
Input
Output
Sample Input
1 2 3 4 5
Sample Output
4
Source
#include<iostream> #include<stdio.h> using namespace std; long long ext_gcd(long long a, long long b, long long *x, long long *y) { if(b==0) { *x = 1,*y = 0; return a; } else { long long r = ext_gcd(b, a%b, x, y); long long t = *x; *x = *y; *y = t - a/b * *y; return r; } } int main() { long long x,y,m,n,l; while(~scanf("%I64d%I64d%I64d%I64d%I64d",&x,&y,&m,&n,&l)) { long long gcd_x,gcd_y; long long gcd = ext_gcd(n-m,l,&gcd_x,&gcd_y); if((x-y)%gcd) { printf("Impossible\n"); continue; } long long ans= gcd_x*(x-y)/gcd; ans=(ans%(l/gcd)+(l/gcd))%(l/gcd); // cout<<(l/gcd)<<endl; printf("%I64d\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/superxuezhazha/p/5762717.html