Cod sursa(job #2551953)
| Utilizator | Data | 20 februarie 2020 13:52:08 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 60 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int prim(long long a)
{
int i;
for(i=2; i*i<=a; i++)
if(a%i==0) return 0;
return 1;
}
int main()
{
long long a, n, b=1, i, exp, aa;
fin >> a >> n;
if(prim(n)==1)
{
exp=n-2; aa=a;
while(exp>1)
{
if(exp%2==1) b=(b*a)%n;
a=(a*a)%n;
exp=exp/2;
}
fout << (a*b)%n;
}
return 0;
}
