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 silverwings at 2010-03-31 11:21:05 on Problem 1061
#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:
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