Cod sursa(job #1121115)

Utilizator killer301Ioan Andrei Nicolae killer301 Data 25 februarie 2014 11:37:22
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.39 kb
#include <cstdio>
#define mod 1999999973

using namespace std;

int main()
{
    freopen("lgput.in", "r", stdin);
    freopen("lgput.out", "w", stdout);
    int n, p, x, power=1;
    scanf("%d%d", &n, &p);
    x=n;
    for(int i=0;(1<<i)<=p;i++)
    {
        if(((1<<i)&p)>0)
            power=(power*x)%mod;
        x=(x*x)%mod;
    }
    printf("%d", power);
    return 0;
}