标签:des style http color os io strong ar
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 90299 | Accepted: 16412 |
Description
Input
Output
Sample Input
1 2 3 4 5
Sample Output
4
Source
学完算法导论第三十一章再来做这个题目吧,so easy!!!
AC代码:
#include<iostream> using namespace std; #define LL long long LL x,y,m,n,L; LL ext_gcd(LL a,LL b,LL &x,LL &y){ if(b==0){ x=1; y=0; return a; } LL ret=ext_gcd(b,a%b,x,y); LL tmp=x; x=y; y=tmp-a/b*y; return ret; } int main(){ LL k,t,d; cin>>x>>y>>m>>n>>L; d=ext_gcd(n-m,L,k,t); if((x-y)%d){ cout<<"Impossible"<<endl; } else{ LL ans=k*(x-y)/d; ans=(ans%(L/d)+L/d)%(L/d); cout<<ans<<endl; } return 0; }
poj 1061(扩展欧几里得),布布扣,bubuko.com
标签:des style http color os io strong ar
原文地址:http://blog.csdn.net/my_acm/article/details/38555095