Cod sursa(job #2145693)
Utilizator | Data | 27 februarie 2018 15:53:33 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <iostream>
#include <fstream>
using namespace std;
typedef unsigned long long int lint;
lint a, b;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
lint Inverse() {
lint x = b - 2, result = 1;
while (x) {
if (x % 2) result = (1ll * result * a) % b;
a = (1ll * a * a) % b;
x /= 2;
}
return result;
}
int main()
{
fin >> a >> b;
fout << Inverse();
return 0;
}