Cod sursa(job #1554434)

Utilizator trettTrett Dragos trett Data 21 decembrie 2015 12:40:37
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.48 kb
#define MOD 1999999973
#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    freopen("lgput.in", "r", stdin);
    //freopen("lgput.out", "w", stdout);
    long long int n, p, rez=1;
    scanf("%lld %lld", &n, &p);
    while(p!=0)
    {
        if(p%2==0)
        {
            n=(n*n)%MOD;
            p/=2;
        }
        else
        {
            p--;
            rez=(rez*n)%MOD;
        }
    }
    printf("%lld", rez);
    return 0;
}