Pagini recente » Cod sursa (job #1517913) | Diferente pentru utilizator/predator5047 intre reviziile 4 si 2 | Cod sursa (job #1322961) | Cod sursa (job #2062510) | Cod sursa (job #2313959)
#include <stdio.h>
void gcd(long long& x, long long& y, int a, int b) {
if (b == 0) {
x = 1;
y = 0;
} else {
gcd(x, y, b, a % b);
long long r = x;
x = y;
y = r - y * (a / b);
}
}
int main() {
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
int a, n;
scanf("%d%d", &a, &n);
long long x = 0, y;
gcd(x, y, a, n);
if (x <= 0)
x = n + x % n;
printf("%d\n", x);
return 0;
}