Pagini recente » Cod sursa (job #624022) | Cod sursa (job #645446) | Cod sursa (job #622589)
Cod sursa(job #622589)
#include<stdio.h>
void euclid(int a,int b,int &x,int &y , int &d)
{
if(b==0)
{
x=1;
y=0;
d=a;
return;
}
int x1 , y1 , q=a/b;
euclid(b,a%b,x1,y1,d);
x=y1;
y=x1-q*y1;
}
int main()
{
int n , i , a , b , c , x , y , d , p;
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
scanf("%d%d",&a,&b);
euclid(a,b,x,y,d);
if(x<0)
{
printf("%d\n",b+x%b);
return 0;
}
else
printf("%d\n",x%b);
}