Cod sursa(job #1745664)

Utilizator delia_ioanaCeapa Delia Ioana delia_ioana Data 22 august 2016 13:54:57
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.49 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include <set>
 
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");

int myPow(int n, int p) {
	if (p < 0)
		return (1 / n) * myPow(1 / n, ((-1) * (p + 1)));
	else if (p == 0)
		return 1;
	else if (p == 1)
		return n;
	else if (p % 2 == 0)
		return myPow(n * n, p / 2);
	else return n * myPow(n * n, (p - 1) / 2);
}

int main() {
	int n, p;
	fin >> n >> p; 
	fout << myPow(n, p) % 1999999973;
	return 0;
}