Cod sursa(job #562714)

Utilizator AndrewTheGreatAndrei Alexandrescu AndrewTheGreat Data 23 martie 2011 19:02:11
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include <stdio.h>

using namespace std;

const int mod = 1999999973;
unsigned long long N, P, rez, next;

int main()
{
    freopen ("lgput.in","r",stdin);
    freopen ("lgput.out","w",stdout);

    scanf("%llu %llu",&N,&P);

    rez = 1;
    while(P)
    {
        if(P & 1)
            rez = (rez * N) % mod;
        N = (N * N) % mod;
        P >>= 1;
    }
    printf("%llu\n",rez);
    return 0;
}