Cod sursa(job #2052002)
Utilizator | Data | 29 octombrie 2017 20:38:56 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.35 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int A,N;
int invm(int x,int y)
{
int s=1;
while(y)
{
if(y%2==1) s=1LL*s*x%N;
y/=2;
x=1LL*x*x%N;
}
return s;
}
int main()
{ fin>>A>>N;
fout<<invm(A,N-2);
return 0;
}