Cod sursa(job #2375793)

Utilizator VadimCCurca Vadim VadimC Data 8 martie 2019 12:12:55
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.42 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int n, p;
const int MOD = 1999999973;

int pow_log(int, int);

int main(){
	fin >> n >> p;
	fout << pow_log(n, p);
}

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