poj 1061 青蛙的约会
2014-02-24 23:39
253 查看
扩展欧几里德算法的练习题,直接调用exgcd函数就可以了
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #define inf 0x7fffffff using namespace std; typedef long long LL; LL x,y,m,n,L; LL x1,y1; LL q; void exgcd(LL a,LL b) { //cout<<a<<endl; if (!b) {x1=1 ;y1=0 ;q=a ; } else { exgcd(b,a%b); LL temp=x1 ;x1=y1 ;y1=temp-a/b*y1; } } LL gcd(LL a,LL b) {return b==0 ? a : gcd(b,a%b); } int main() { while (cin>>x>>y>>m>>n>>L) { LL d=y-x; LL gcd=1; exgcd(n-m,L); gcd=q; if (d%gcd) cout<<"Impossible"<<endl; else { x1 *= (x-y)/gcd; x1=(x1%(L/gcd)+(L/gcd))%(L/gcd); cout<<x1<<endl; } } return 0; }
相关文章推荐
- poj 1061 青蛙的约会(扩展欧几里德)
- 青蛙约会 poj 1061
- POJ 1061 青蛙的约会(扩欧)
- 【poj1061】青蛙的约会(数论,exgcd)
- poj 1061 小白算法练习 数论 扩展欧几里得 青蛙的约会
- 【POJ】[1061]青蛙的约会
- POJ 1061 青蛙的约会
- Poj 1061:青蛙的约会(扩展欧几里得)
- 【扩展欧几里得】poj 1061 青蛙的约会
- [数论] 拓展欧几里得算法 (poj1061 青蛙的约会)
- 【POJ】【1061】/【BZOJ】【1477】青蛙的约会
- POJ - 1061 - 青蛙的约会 (扩展欧几里得)
- 青蛙的约会 poj 1061
- poj1061青蛙的约会 同余方程
- POJ 1061 青蛙的约会
- POJ - 1061 青蛙的约会(拓展GCD
- poj 1061 青蛙的约会
- poj 1061 青蛙的约会 数论 线性同余
- 青蛙的约会 POJ - 1061 拓展欧几里得
- POJ 1061 青蛙的约会(扩展欧几里德)