Cod sursa(job #1944980)
| Utilizator | Data | 29 martie 2017 12:24:46 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <fstream>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
ll a, n;
ll exp(int x, int y) {
ll r = 1;
for (ll i = 1; i <= y; i <<= 1) {
if (i & y) {
r *= x;
r %= n;
}
x *= x;
x %= n;
}
return r;
}
int main() {
fin >> a >> n;
fout << exp(a, n - 2);
fout.close();
return 0;
}
