Pagini recente » Cod sursa (job #1096188) | Cod sursa (job #362305) | Cod sursa (job #1426219) | Cod sursa (job #926272) | Cod sursa (job #1785511)
#include <stdio.h>
int a, n;
void euclid(int a, int b, int* x, int* y){
if(b == 0){
*x = 1;
*y = 0;
return;
}
int x0, y0;
euclid(b, a % b, &x0, &y0);
*x = y0;
*y = x0 - (a / b) * y0;
}
int main(){
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
scanf("%d%d", &a, &n);
int x, y;
euclid(a, n, &x, &y);
while(x < 0)
x += n;
printf("%d\n", x);
return 0;
}