Cod sursa(job #226591)

Utilizator filipbFilip Cristian Buruiana filipb Data 2 decembrie 2008 00:38:32
Problema Invers modular Scor Ascuns
Compilator cpp Status done
Runda Marime 0.42 kb
#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;
}