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 jedi2009 at 2009-05-13 12:20:14 on Problem 1061
#include <stdio.h>

typedef struct
{
	long long d,x0,y0;
}Node;

Node Extended_Euclid(long long a,long long b)
{
	if(b==0) return (Node){a,1,0};
	Node temp=Extended_Euclid(b,a%b);
	return (Node){temp.d,temp.y0,temp.x0-(a/b)*temp.y0};
}

int main()
{
	long long x,y,m,n,l;
	scanf("%lld %lld %lld %lld %lld",&x,&y,&m,&n,&l);
	long long c;
	if(x>y) 
	{
		long long temp1,temp2;
		temp1=x;temp2=m;
		x=y;m=n;
		y=temp1;n=temp2;
	}
	if(m>n) c=y-x;
	else c=x-y+l;
	Node last=Extended_Euclid(abs(m-n),l);
        if(c%last.d||m==n) printf("Impossible\n");
	else
	{
		long long xx=c*last.x0/last.d;
		xx%=l/last.d;
		if(xx<0) xx+=l/last.d;
		printf("%lld\n",xx);
	}
	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