Pagini recente » Cod sursa (job #1803900) | Cod sursa (job #2177269) | Cod sursa (job #1985511) | Cod sursa (job #3273280) | Cod sursa (job #228206)
Cod sursa(job #228206)
#include <stdio.h>
#define ll long long
int N, P;
int put(int a, int b)
{
if (!b)
return 1;
int x = put(a, b/2);
x = ((ll)x*x) % P;
if (b & 1)
x = ((ll)x * a) % P;
return x;
}
int main()
{
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
scanf("%d %d", &N, &P);
printf("%d\n", put(N, P-2));
return 0;
}