标签:des style class blog c code
Description
Input
Output
Sample Input
1 2 3 4 5
Sample Output
4
代码:
#include <iostream> #include <cstdio> #include <cmath> using namespace std; typedef long long LL; LL gcd(LL m,LL n) { LL r=m%n; while(r) { m=n; n=r; r=m%n; } return n; } LL ex_gcd(LL a,LL b,LL &x,LL &y) { if(b==0) { x=1; y=0; return a; } LL d=ex_gcd(b,a%b,x,y); LL t=x; x=y; y=t-a/b*y; return d; } int main() { LL x,y,m,n,a,b; while(cin>>x>>y>>m>>n>>b) { LL R=x-y; LL a=n-m; x=1,y=1; LL r=gcd(a,b); if(R%r) { printf("Impossible\n"); continue; } ex_gcd(a,b,x,y); LL s=b/r; x=x*R/r; x=(x%s+s)%s; cout<<x<<endl; } return 0; }
poj 1061 青蛙的约会(拓展欧几里德),布布扣,bubuko.com
标签:des style class blog c code
原文地址:http://blog.csdn.net/knight_kaka/article/details/26492099