Pagini recente » Cod sursa (job #1500666) | Rating Ilinca Andrei Alexandru (Ilinca_Andrei) | Monitorul de evaluare | Rating Ianos Alex-Marian (aeru1) | Cod sursa (job #1413536)
#include <cstdio>
using namespace std;
int a, n, sol;
int pow (int x, int y)
{
if (y==1) return x % n;
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);
}