Cod sursa(job #1895819)
Utilizator | Data | 28 februarie 2017 11:13:32 | |
---|---|---|---|
Problema | Invers modular | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <fstream>
#include <math.h>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
unsigned long long a,b,nr=1,copie;
unsigned long i;
int main()
{
f>>a>>b;
int ok=1;
copie=b;
for(int k=2;k<=sqrt(b)&&ok;k++)
if(b%k==0) ok=0;
b--;
if(ok) b--;
while(b)
{
if(b&1)
{
nr*=a;
}
a*=a;
b>>=1;
}
g<<nr%copie;
return 0;
}