Cod sursa(job #793247)

Utilizator Sm3USmeu Rares Sm3U Data 2 octombrie 2012 13:28:18
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.44 kb
#include <cstdio>
#define mod 1999999973

using namespace std;

int n;
int p;

int pow (int p){
    if (p == 1){
        return n;
    }
    int x = pow (p / 2);
    x = x * x;
    if (p % 2 == 0){
        return x % mod;
    }
    return x * n % mod;

}

int main()
{
    freopen ("lgput.in", "r", stdin);
    freopen ("lgput.out", "w", stdout);
    scanf ("%d %d", &n, &p);
    printf ("%d", pow(p));

    return 0;
}