| ||||||||||
| 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>
long ee(long a, long b, long *x, long *y)
{
if (a < b)
return ee(b, a, y, x);
if ( b == 0 )
{
*x = 1;
*y = 0;
return a;
}
else
{
long gcd, tx, ty;
gcd = ee(b, a % b, &tx, &ty);
*x = ty;
*y = tx - (a/b) * ty;
return gcd;
}
}
long mle(long a, long b, long n)
{
long x, y, d;
d = ee(a, n, &x, &y);
if (b % d)
printf("Impossible\n");
else
{
x = x * (b/d) % (n/d);
if (x < 0)
x += n/d;
printf("%ld\n", x);
}
}
int main()
{
long x, y, m, n, l, gcd, distance, leap;
while(scanf("%ld %ld %ld %ld %ld", &x, &y, &m, &n, &l)!=EOF)
{
distance = y - x;
distance = (distance % l + l) % l;
leap = m - n;
leap = (leap % l + l) % l;
mle(leap, distance, l);
}
return 0;
}
有一帖测试数据,试了一下都对的(那贴楼主给的结果不对,我看一些回复确认是对的)
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator