Cod sursa(job #2140226)
Utilizator | Data | 23 februarie 2018 08:38:54 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
long long a, mod;
void invmod(long long x)
{
int var=mod-2, rez=1;
while(var)
{
if( var%2 == 0 )
{
rez = (1LL*x*rez)%mod;
}
x = (1LL*x*x)%mod;
var /= 2;
}
return rez;
}
int main()
{
f >> a >> mod;
invmod(a);
return 0;
}