Cod sursa(job #1095419)
| Utilizator | Data | 30 ianuarie 2014 22:03:37 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 60 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
long long a, mod;
int pow(int a, long long exp)
{
int rez = 1;
while (exp) {
if (exp & 1) {
rez = (1LL * rez * a) % mod;
}
exp >>= 1;
a = (1LL * a * a) % mod;
}
return rez;
}
int main()
{
f >> a >> mod;
a %= mod;
g << pow(a, mod - 2);
}
