Cod sursa(job #2178777)

Utilizator silvereaLKovacs Istvan silvereaL Data 19 martie 2018 18:30:00
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <iostream>
#include <fstream>

using namespace std;

const long long MOD = 1999999973;

ifstream fcin("lgput.in");
ofstream fcout("lgput.out");

unsigned long long power(unsigned long long x,unsigned long long y)
{
    if (y == 0)
        return 1;
    if (y == 1)
        return x;

    if (y % 2)
        return (x % MOD * power((x * x) % MOD, y / 2)) % MOD;
    return power((x * x) % MOD, y / 2) % MOD;
}

int main()
{
    unsigned long long N, P;
    fcin >> N >> P;
    fcout << power(N, P) % MOD;
}