Pagini recente » Cod sursa (job #2253857) | Cod sursa (job #1393258) | Cod sursa (job #2538401) | Cod sursa (job #3135633) | Cod sursa (job #355458)
Cod sursa(job #355458)
#include <stdio.h>
void gcd(int a, int b, long long &x, long long &y)
{
long long x0, y0;
if(b==0)
{
x=1; y=0;
}
else { gcd(b, a%b, x0, y0);
x=y0;
y=x0-(a/b)*y0;}
}
int main()
{
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
int a, n;
scanf("%d %d", &a, &n);
long long x, y;
gcd(a, n, x,y );
if(x<=0)
x=n+x%n;
printf("%lld\n",x);
return 0;
}