Cod sursa(job #1809926)
| Utilizator | Data | 19 noiembrie 2016 13:43:16 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include<cstdio>
FILE *fin, *fout;
long long a,n;
long long x,y;
void gcd(long long a, long long b) {
long long aux;
if (!b)
{
x=1;
y=0;
}
else
{
gcd(b,a%b);
aux=x;
x=y;
y=aux-y*(a/b);
}
}
int main() {
fin = fopen("inversmodular.in", "r");
fout = fopen("inversmodular.out", "w");
fscanf(fin, "%d%d", &a, &n);
gcd(a,n);
if(x <= 0)
x = n + x % n;
fprintf(fout, "%d", x);
fclose(fin);
fclose(fout);
return 0;
}
