Cod sursa(job #2124410)
Utilizator | Data | 7 februarie 2018 10:51:55 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
long long a,n,x,R,b;
int main()
{
long long i;
in>>a>>n;
a=a%n;
b=n-2;
R=1;
while(b)
{
if(b%2==1)
R=(R*a)%n;
a=(a*a)%n;
b=b/2;
}
out<<R;
return 0;
}