标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 103802 | Accepted: 20198 |
Description
Input
Output
Sample Input
1 2 3 4 5
Sample Output
4
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 typedef long long LL; 6 using namespace std; 7 LL x,y,m,n,l; 8 LL x0; 9 LL exgcd(LL a,LL b,LL &x,LL &y) 10 { 11 LL d=a; 12 if(b!=0) 13 { 14 d=exgcd(b,a%b,y,x); 15 y-=(a/b)*x; 16 } 17 else 18 { 19 x=1; 20 y=0; 21 } 22 return d; 23 } 24 LL tt; 25 int modular_linear_equation(LL a,LL b,LL n) 26 { 27 LL x,y; 28 LL d=exgcd(a,n,x,y); 29 if(b%d) 30 return -1; 31 x=x*(b/d); 32 LL r=n/d; 33 x=(x%r+r)%r; 34 tt=x; 35 return 1; 36 } 37 int main() 38 { 39 while(cin>>x>>y>>m>>n>>l) 40 { 41 if(modular_linear_equation(n-m,x-y,l)==-1) 42 cout<<"Impossible"<<endl; 43 else 44 cout<<tt<<endl; 45 } 46 return 0; 47 }
标签:
原文地址:http://www.cnblogs.com/a1225234/p/5471577.html