Cod sursa(job #1590035)
Utilizator | Chris Luntraru Brandon | Data | 4 februarie 2016 17:38:11 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.52 kb |
#include <fstream>
using namespace std;
ifstream cin ("lgput.in");
ofstream cout ("lgput.out");
long long n, p;
long long pow(int n, int p) {
if(p == 0) {
return 1;
}
if(p == 1) {
return n;
}
if(p % 2 == 0) {
int x = pow(n, p / 2);
return x * x;
}
else {
return n * pow(n, p - 1);
}
}
void read() {
cin >> n >> p;
}
void print() {
cout << pow(n, p);
}
int main() {
read();
print();
return 0;
}