Cod sursa(job #2034166)
Utilizator | Data | 7 octombrie 2017 15:34:48 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
ll exp_log(ll n,ll e,ll mod)
{
ll sol=1;
while (e!=0)
{
if (e%2==1) sol=sol*n%mod;
n=n*n%mod;
e/=2;
}
return sol%mod;
}
int main()
{
ll a,n;
f>>a>>n;
g<<exp_log(a,n-2,n);
return 0;
}