| ||||||||||
| 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 "stdafx.h"
#include <stdio.h>
#include <math.h>
long Gcd(long a, long b)
{
if(b==0) return a;
return Gcd(b,a%b);
}
void exGcd( long a, long b,long &m,long &n)
{
if(b==0)
{
m=1;
n=0;
return;
}
exGcd(b,a%b,m,n);
long tmp;
tmp=m;
m=n;
n=tmp-(a/b)*n;
}
int main ()
{
long x,y,
m,n,
l,
a,b,
step,round,
gcd,tmp;
scanf("%d %d %d %d %d",&x,&y,&m,&n,&l);
a=(n-m);
b=(x-y);
gcd=Gcd(a,l);
if(b%gcd)
{
printf("Impossible\n");
getchar();
return 0;
}
a/=gcd;
l/=gcd;
b/=gcd;
exGcd(a,l,step,round);
tmp=b*step/l;
step=b*step-tmp*l;
if(step<0)
step+=l;
printf("%d ",step);
return 0;
}
给的测试数据都过了啊~为什么会WA~
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator