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

help!!!

Posted by fdfzq at 2004-02-06 14:20:50 on Problem 1061
#include<iostream.h>
#include<iomanip.h>
//x,y用于gcd函数满足:aa*x+nn*y==gcd(aa,nn)
//gcd返回的值为answer即gcd(cc,dd)==answer
//e为aa*x==bb(mod nn)的解
long int x,y,e;
long int gcd(long int aa,long int bb)
{
	long int t;
	long int answer;
	if(bb==0)
	{
		answer=aa;
		x=1;
		y=0;
	}
	else
	{
		answer=gcd(bb,aa%bb);
		t=x;
		x=y;
		y=t-(aa/bb)*y;
	}
	return answer;
}
void tongyu(long int aa,long int bb,long int nn)
{
	long int d,i,ee;
	d=gcd(aa,nn);
	if(bb%d>0)
	{
		e=-1;
		return;
	}
	else
	{
		e=(x*(bb/d))%nn;
		if(e<0)
			e=e+nn;
		
	}
}
int main()
{long int x1,y1,x2,y2,m,n,l,b;

cin>>x2>>y2>>m>>n>>l;
cout << setprecision(0);
cout << setiosflags(ios::fixed);
  x1=x2%l;
  y1=y2%l;
  if(m>=n)
  {
	  if(y1>=x1)
		  b=y1-x1;
	  else
		  b=y1-x1+l;
	  tongyu(m-n,b,l);
      if(e==-1)
	  {
	  cout<<"Impossible"<<endl;
	  }
      else
	  {
	     cout<<e<<endl;
	  }
  }
  if(m<n)
  {
	  if(x1>=y1)
	  {
		  b=x1-y1;
	  }
	  else
		  b=x1-y1+l;
	  tongyu(n-m,b,l);
	  if(e==-1)
	  {
	  cout<<"Impossible"<<endl;
	  }
      else
	  {
	     cout<<e<<endl;
	  }
  }

  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