Cod sursa(job #2033996)
Utilizator | Data | 7 octombrie 2017 12:43:10 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.51 kb |
#include <iostream>
#include <fstream>
#include <math.h>
#define MOD 1000000007
using namespace std;
ifstream in ("inversmodular.in");
ofstream out ("inversmodular.out");
long long expow (long long b, long long e, long long mod)
{
int ans=1;
while (e>0)
{
if (e % 2)
ans=ans*b%mod;
b = b * b % mod;
e/=2;
}
return ans;
}
int main()
{
long long a,n,x;
in>>a>>n;
x=expow(a,n-2,n);
cout<<x;
out<<x;
return 0;
}