Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我的程序为什么 WA 呢?高手帮看看?

Posted by yuest at 2009-08-13 16:12:15 on Problem 1061
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator