Cod sursa(job #3143729)
| Utilizator | Data | 1 august 2023 19:42:13 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.59 kb |
#include <bits/stdc++.h>
using namespace std;
int mod;
int lgpow(int base, int exponent)
{
int result = 1;
while (exponent)
{
if (exponent % 2)
result = result * base % mod;
base = base * base % mod;
exponent /= 2;
}
return result;
}
int main()
{
#ifndef TEST
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
#endif
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int a;
cin >> a >> mod;
cout << lgpow(a, mod - 2) % mod;
return 0;
}