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

请教大神!!!!!!

Posted by 20092378 at 2010-07-22 18:22:16
#include"iostream"
#include"cmath"				
using namespace std;
int main()
{
	int i,a,b,n,k,t,t1,t2,sign1,sign2,x0,y0,x1,y1,x,y,gcd,z1,z2;
   scanf("%d%d%d%d%d",&x,&y,&x1,&y1,&t);
 	a=x1-y1;z2=b=-t;n=y-x;
    sign1=a>0?1:-1;sign2=b>0?1:-1;
	a=abs(a);b=abs(b);
	x=a;y=b;
	while(y!=0)
	{
		k=y;
		y=x%y;
		x=k;
	}
	gcd=x;
	if(n%gcd!=0)
	{
		printf("Impossible\n");
	    return 0;
	}
	a=a/gcd;b=b/gcd;n=n/gcd;
	x0=1;y0=0;x1=0;y1=1;
	while(1)
	{
      k=a/b;t=a%b;
	  t1=x1;t2=y1;
	  x1=x0-k*x1;y1=y0-k*y1;
	  x0=t1;y0=t2;
	  if(a%b==1) break;
	  a=b;b=t;
	}
    z1=x1*sign1*n;
     z1=z1%abs(z2/gcd);
	 if(z1<0)
		 z1+=abs(z2/gcd);
    printf("%d\n",z1);
   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