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 oushuai110 at 2010-07-30 11:35:55 on Problem 1061
#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:
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