Pagini recente » Cod sursa (job #185766) | Statistici Andra Gheorghe (Andra_Gheorghe12) | Cod sursa (job #1910839) | Cod sursa (job #3255522) | Cod sursa (job #1413559)
#include <cstdio>
using namespace std;
int a, n, sol;
int pow (int x, int y)
{
if (y==1) return x;
else if (y%2==0) return pow (x*x, y/2) % n;
else return x * pow (x*x, y/2) % n;
}
int main()
{
freopen ("inversmodular.in", "r", stdin);
freopen ("inversmodular.out", "w", stdout);
scanf ("%d%d", &a, &n);
sol=pow (a, n-2)%n;
printf ("%d", sol);
}