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 conquerer at 2007-04-01 21:48:19 on Problem 1061
#include<iostream>
using namespace std;
long  ext_euclid(long  a,long  b,long  &x,long  &y)  
{  
     long  t,d;  
     if  (b==0)  {x=1;y=0;return a;}
     d=ext_euclid(b,a  %b,x,y);  
     t=x;  
     x=y;  
     y=t-a/b*y;  
     return  d; 
} 
int main()
{long x,y,m,n,l,d,x1,y1,a1,b1;
 while(cin>>x>>y>>m>>n>>l)
 {d=ext_euclid(n-m,  l,  x1,  y1);  
  if((x-y)%d!=0)    
       printf("Impossible\n"); 
  else
  {x1=x1*((x-y)/d);  y1=y1*((x-y)/d); a1=(n-m)/d; b1=l/d;
    while(x1>0)  x1-=b1; x1+=b1;
   while(x1<0)  x1+=b1;
   printf("%d\n",x1);
  }
 }
 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