Cod sursa(job #2018759)
Utilizator | Data | 5 septembrie 2017 21:26:23 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.52 kb |
#include <fstream>
using namespace std;
int x, modulo;
int Invers_Modular(int m)
{
int putere = m - 2;
int sol = 1;
while(putere > 0)
{
if(putere & 1) sol = (1LL * sol * x) % m;
x = (1LL * x * x) % m;
putere >>= 1;
}
return sol;
}
int main()
{
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
f >> x >> modulo;
g << Invers_Modular(modulo);
return 0;
}