Cod sursa(job #2033857)
Utilizator | Data | 7 octombrie 2017 11:19:07 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
long long ceva(long long b, long long e, long long mod)
{
long long ceva2=1;
while(e>0)
{
if(e%2)
ceva2=ceva2*b%mod;
b = b*b%mod;
e/=2;
}
return ceva2;
}
int main()
{
int a,n;
in >> a >> n;
out << ceva(a, n - 2, n);
return 0;
}