Pagini recente » Cod sursa (job #1936766) | Cod sursa (job #1121015) | Cod sursa (job #2168644) | Cod sursa (job #2075907) | Cod sursa (job #359012)
Cod sursa(job #359012)
#include <stdio.h>
inline void gcd(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
return;
}
int d,x0,y0;
gcd(b, a % b,x0,y0);
x = y0;
y = x0 - (a/b)*y0;
}
int main()
{
int x,y,a,b;
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
scanf("%d%d",&a,&b);
gcd(a,b,x,y);
if (x < 0)
{
x = b + x % b;
}
printf("%d",x);
return 0;
}