Cod sursa(job #1800262)

Utilizator msciSergiu Marin msci Data 7 noiembrie 2016 17:01:33
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.49 kb
#include <iostream>
#include <fstream>
using namespace std;

const long long MOD = 1999999973;

ifstream fin("lgput.in");
ofstream fout("lgput.out");

long long pow(long long x, long long n) {
    long long y = 1;
    while (n > 1) {
        if (n % 2 == 0) {
            x *= x; x %= MOD; n /= 2;
        } else {
            y *= x; y %= MOD; x *= x; x %= MOD; n = (n - 1) / 2;
        }
    }
    return (x * y) % MOD;
}

int main() {
    int N, P; fin >> N >> P;
    fout << pow(N, P) << endl;
}