Cod sursa(job #1591878)

Utilizator sebii_cSebastian Claici sebii_c Data 6 februarie 2016 19:57:02
Problema Ridicare la putere in timp logaritmic Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include <fstream>

using namespace std;

const long long mod = 1999999973;

template <class T>
T pow(T x, int n) {
    if (n == 0) return 1;
    if (n == 1) return x % 1999999973;

    T half = pow(x, n / 2);
    return (half * half * (n % 2 ? x : 1)) % 1999999973;
}

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

    long long x, n; fin >> x >> n;
    fout << pow(x, n) << endl;

    return 0;
}