Cod sursa(job #487292)
| Utilizator | Data | 24 septembrie 2010 17:33:04 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.4 kb |
#include <stdio.h>
#include <math.h>
long n, m, put;
long long val, rez;
int main() {
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
scanf("%ld %ld", &n, &m);
put = m - 2; rez = 1; val = n;
while (put) {
if (put & 1) {
rez *= 1LL * val;
rez %= m * 1LL;
}
put >>= 1;
val *= 1LL * val;
}
printf("%lld\n", rez);
return 0;
}
