Cod sursa(job #1618020)

Utilizator mariapascuMaria Pascu mariapascu Data 27 februarie 2016 17:39:26
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.47 kb
#include <fstream>
using namespace std;

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

const int MOD = 1999999973;
long long int n, p;

int Pow(int n, int p);

int main() {
    fin >> n >> p;
    fout << Pow(n, p);
    fin.close();
    fout.close();
    return 0;
}

int Pow(int n, int p) {
    if (p == 0) return 1;
    int x = (1LL * (Pow(n, p / 2) % MOD) * (Pow(n, p / 2) % MOD)) % MOD;
    if (p % 2 == 1) x = (1LL * x * n) % MOD;
    return x;
}