Pagini recente » Cod sursa (job #3185967) | Cod sursa (job #825239) | Cod sursa (job #23620) | Cod sursa (job #3274013) | Cod sursa (job #1146328)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
void euclid(int a, int b, int &d, int &x, int &y)
{
if(b == 0)
{
d = a;
x = 1;
y = 0;
return;
}
int x0, y0;
euclid(b, a%b, d, x0, y0);
x = y0;
y = x0 - y0*(a/b);
}
int main()
{
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
int n, a;
scanf("%d%d", &a, &n);
int d, x, y;
euclid(n, a, d, x, y);
while(y < 0)
y += n;
printf("%d\n", y);
return 0;
}