标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 93461 | Accepted: 17231 |
Description
Input
Output
Sample Input
1 2 3 4 5
Sample Output
4
Source
分析:扩展欧几里得
学习网址:http://www.cnblogs.com/comeon4mydream/archive/2011/07/18/2109060.html
1 #include<iostream> 2 #include<queue> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 using namespace std; 7 typedef long long ll; 8 ll extgcd(ll a,ll b,ll &x,ll &y){ 9 if(b==0){ 10 x=1;y=0; 11 return a; 12 } 13 ll d=extgcd(b,a%b,x,y); 14 ll t; 15 t=x;x=y;y=t-a/b*x; 16 return d; 17 } 18 int main(){ 19 ll x,y,m,n,L; 20 while(cin>>x>>y>>m>>n>>L){ 21 ll a,b,c,d; 22 a=n-m; 23 b=L; 24 c=x-y; 25 if(c%(d=extgcd(a,b,x,y))){ 26 cout<<"Impossible\n"; 27 } 28 else{ 29 x*=c/d; 30 ll r=b/d; 31 x=(x%r+r)%r; 32 cout<<x<<endl; 33 } 34 } 35 return 0; 36 }
标签:
原文地址:http://www.cnblogs.com/Deribs4/p/4285178.html