Pagini recente » Cod sursa (job #2581274) | Cod sursa (job #3197140) | Cod sursa (job #891932) | Cod sursa (job #1880556) | Cod sursa (job #2666721)
// 1. EUCLID EXTINS
#include <stdio.h>
#include <stdlib.h>
void euclid (int a, int b, int *d, int *x, int *y){
if (b == 0){
*d = a;
*x = 1;
*y = 0;
}else{
int x0, y0;
euclid(b, a % b, d, &x0, &y0);
*x = y0;
*y = x0 - (a / b) * y0;
}
}
int main()
{
FILE *fin, *fout;
fin = fopen("inversmodular.in", "r");
fout = fopen("inversmodular.out", "w");
int a, n;
fscanf(fin, "%d%d", &a, &n);
int x, y, d;
euclid(a, n, &d, &x, &y);
if (x <= 0) x = n + (x % n);
fprintf(fout, "%d", x);
return 0;
}