Cod sursa(job #2034159)
Utilizator | Data | 7 octombrie 2017 15:27:35 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <bits/stdc++.h>
#include <limits>
using namespace std;
typedef unsigned long long ll;
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*=n%mod;
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;
}