Cod sursa(job #1413583)
Utilizator | Data | 1 aprilie 2015 22:59:03 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#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);
else return x * pow (x*x, y/2);
}
int main()
{
freopen ("inversmodular.in", "r", stdin);
freopen ("inversmodular.out", "w", stdout);
scanf ("%d%d", &a, &n);
sol=pow (a, n-2);
printf ("%d", sol);
}