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 cug_fish2008 at 2008-12-03 17:05:10 on Problem 1061
#include <iostream>
using namespace std;
void Euclid(long long a,long long b,long long &x0,long long &y0);
long long gcd(long long a,long long b);
int main()
{
	long long x,y,m,n,l;
	cin>>x>>y>>m>>n>>l;
	long long a,b,c;
	if(m==n)goto eixt;
	if(x>=l)x%=l;
	if(y>=l)y%=l;
	if(m>n){a=m-n;c=y-x;}
	else {a=n-m;c=x-y;}
	b=l;
	long long p;
	p=gcd(a,b);
	if(c%p!=0)goto eixt;
	if(p!=1)
	{a/=p;b/=p;c/=p;}
	Euclid(a,b,x,y);
	x*=c;
	while(x<=0)x+=b;
	cout<<x;goto over;
eixt:
	cout<<"Impossible";
over:
	return 0;
}
long long gcd(long long a,long long b)
{
	if(b==0)return a;
	gcd(b,a%b);
}
void Euclid(long long a,long long b,long long &x0,long long &y0)  
{  
     long long t;  
     if (b==0)
	 {
		 x0=1;y0=0;
		 return ;
	 }
     Euclid(b,a%b,x0,y0);  
	 t=x0;  
     x0=y0;  
     y0=t-(a/b)*y0;  
     return ; 
}

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