Cod sursa(job #2140215)
Utilizator | Data | 23 februarie 2018 07:54:02 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
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 a;
long long inv=0, ins=0;
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;
}