Pagini recente » Cod sursa (job #1607803) | Borderou de evaluare (job #2627393) | Cod sursa (job #462111) | Cod sursa (job #1358593) | Cod sursa (job #2654826)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int LogP(int a, int n, int P)
{
int rez = 1;
while(n > 0)
{
if (n % 2 == 1)
rez = 1LL * rez * a % P;
n /= 2;
a = 1LL * a * a % P;
}
return rez;
}
int main()
{
long long a, P;
fin >> a >> P;
fout << LogP(a, P - 2, P);
return 0;
}