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

Re:如果遇到 好人帮忙 指点一下啊!(代码)

Posted by starwind at 2008-12-07 16:06:11 on Problem 1061
In Reply To:如果遇到 好人帮忙 指点一下啊!(代码) Posted by:cug_fish2008 at 2008-12-02 20:00:17
> #include <iostream>
> using namespace std;
> long gcd(long m,long n,long l);
> int main()
> {
> 	long x,y,m,n,l;
> 	cin>>x>>y>>m>>n>>l;
> 	long q;
> 	if(y>x)q=y-x;
> 	else q=x-y;
> 	if(m==n||q%gcd(m,n,l)!=0)
> 		cout<<"Impossible";
> 	long a,b,c;
> 	a=m-n;c=y-x;
> 	long long k;
> 	for(b=1;b<l;b++)
> 	{
> 		k=a*b-c;
> 		if(k%l==0)
> 		{cout<<b;break;}
> 	}
> 	return 0;
> }
> long gcd(long m,long n,long l)
> {
> 	long k;
> 	if(m-n<0)k=n-m;
> 	else k=m-n;
> 	long a,b;
> 	if(k>=l){a=k;b=l;}
> 	else {a=l;b=k;}
> 	long q,r;
> 	do
> 	{	
> 		q=a/b;r=a%b;
> 		a=b;b=r;
> 	}while(r!=0);
> 	return a;
> }

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