Pagini recente » Cod sursa (job #1543100) | Cod sursa (job #1858850) | Cod sursa (job #3259596) | Cod sursa (job #1646286) | Cod sursa (job #1900427)
#include <stdio.h>
void InvMod(int a, int b, int &x, int &y){
if(b == 0){
x = 1;
y = 0;
}else{
int x0, y0;
InvMod(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main(){
int inv = 0, ins, A, N;
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
scanf("%d %d", &A, &N);
InvMod(A, N, inv, ins);
if(inv <= 0) inv = N + inv % N;
printf("%lld\n", inv);
return 0;
}