Cod sursa(job #1800242)

Utilizator msciSergiu Marin msci Data 7 noiembrie 2016 16:50:36
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <bits/stdc++.h>

using namespace std;

const long long MOD = 1999999973;

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

int main() {
    cin.sync_with_stdio(false);
    ifstream fin;
    ofstream fout;
    fin.open("lgput.in");
    fout.open("lgput.out");
    int N, P; fin >> N >> P;
    fout << pow(N, P) << endl;
}