Cod sursa(job #3283365)
Utilizator | Data | 9 martie 2025 13:09:00 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int A, N;
int LogExpo(int a, int b)
{
int P = 1;
while (b > 0)
{
if (b % 2 == 1)P = 1LL * P * a % N;
b /= 2;
a = 1LL * a * a % N;
}
return P;
}
int main()
{
fin >> A >> N;
fout << LogExpo(A, N - 2);
return 0;
}