Cod sursa(job #1379020)
Utilizator | Data | 6 martie 2015 15:44:13 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
long long int rez=1,a,mod;
void putlog(long long int a, long long int b)
{
while(b)
{
if(b%2==1)
{
rez=(rez*a)%mod;
b--;
}
a=a*a;
a%=mod;
b/=2;
}
}
int main()
{
fin>>a>>mod;
putlog(a,mod-2);
fout<<rez;
return 0;
}