Cod sursa(job #3132896)
Utilizator | Data | 24 mai 2023 11:29:44 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
ll exp_log(ll x, ll n)
{
if(n == 0) return 1;
if(n%2 == 0) return exp_log(x*x, n/2);
return x*exp_log(x*x, n/2);
}
int main()
{
ll a, n;
cin >> a >> n;
cout << exp_log(a, n-2)%n;
return 0;
}