| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
我的TL程序In Reply To:扩展欧几里德算法 Posted by:sunmoonstar at 2006-12-08 14:33:34 就是选最小正整数那里不是太会
#include <stdio.h>
struct node
{
int d,x,y;
};
struct node gcd(int a,int b)
{
struct node c;
int e;
if(b==0)
{
c.d=a;
c.x=1;
c.y=0;
return(c);
}
else
{
c=gcd(b,a%b);
e=c.x;
c.x=c.y;
c.y=e-(a/b)*c.y;
return(c);
}
}
main()
{
int i,m,n,a,b,l,x,min;
struct node c;
scanf("%d%d%d%d%d",&a,&b,&m,&n,&l);
if(m>n) c=gcd(m-n,l);
else c=gcd(m-n+l,l);
if((b-a)%(c.d)==0)
{
x=(c.x*((b-a)/c.d))% l;
if(x<0) x+=l;
min=x;
for(i=0;i<c.d;i++)
{
x=(x+i*(l/c.d))%l;
if(x<0) x+=l;
if(x<min) min=x;
}
printf("%d\n",min);
}
else printf("Impossible\n");
return(0);
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator