Cod sursa(job #705419)
Utilizator | Data | 4 martie 2012 11:49:16 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <cstring>
#include <cstdio>
#include <cmath>
long long a, b;
long long megold(long long a, long long b) {
long long ax = 1, bx = 0, cx, d, r;
while (b) {
d = a / b;
r = a % b;
cx = bx;
bx = ax - d * bx;
ax = cx;
a = b;
b = r;
}
return(ax);
}
int main() {
FILE * in = fopen("inversmodular.in", "rt");
FILE * out = fopen("inversmodular.out", "wt");
fscanf(in, "%lld%lld", &a, &b);
fprintf(out, "%lld", megold(a, b));
fclose(in);
fclose(out);
}