Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
这组数据输出 -1 都过了,,,,,,,,,,无语#include<iostream> #include<stdio.h> #include<cmath> using namespace std; long long int gcd(long long int a,long long int b,long long int &x,long long int &y){ if (b==0){ x=1,y=0; return a; } int q=gcd(b,a%b,y,x); y-=a/b*x; return q; } int main() { long long int x,y,m,n,l; while(scanf("%I64d%I64d%I64d%I64d%I64d",&x,&y,&m,&n,&l)!=EOF) { long long int a=(n-m),c=(x-y),x0,y0; long long int g=gcd(a,l,x0,y0); if(n==m||c%g!=0) { cout<<"Impossible"<<endl; }else { x0=x0*(c/g); int b=l/g; x0=(x0%b+b)%b; cout<<x0<<endl; } } return 0; } 9 8 7 6 4 -1 Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator