Cod sursa(job #2086210)
Utilizator | Data | 11 decembrie 2017 17:36:57 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
long long x, MOD;
int invmod(int x)
{
long long put=MOD-2,rez=1;
while(put)
{
if(put%2)
{
rez=(1LL*x*rez)%MOD;
}
x=(1LL*x*x)%MOD;
put/=2;
}
return rez;
}
int main()
{
f >> x >> MOD;
g <<invmod(x);
return 0;
}