| ||||||||||
| 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 | |||||||||
怎么总是wa 郁闷#include<stdio.h>
void answer(long int a,long int b,long &x,long int &y)
{
if(!b)
{
x=1;
y=0;
}
else
{
int t;
answer(b,a%b,x,y);
t=x;
x=y;
y=t-y*(a/b);
}
}
long int gcd(long int a,long int b)
{
if(!b)
return a;
else
return gcd(b,a%b);
}
int main()
{
long int n,m,x,y,l,t,p,k;
long int a,b,c,d;
scanf("%ld%ld%ld%ld%ld",&x, &y, &m, &n, &l);
a=n-m;b=l;c=x-y;
d=gcd(a,b);
if(!d)
printf("Impossible\n");
else
{
a/=d;b/=d;c/=d;
answer(a,b,t,p);
k=t*c/b;
t=c*t-k*b;
while(t<0)
t+=b;
printf("%ld\n",t);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator