Cod sursa(job #930724)
| Utilizator | Data | 27 martie 2013 19:51:11 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
long long power(int base, int exp) {
if (exp == 1)
return base;
long long multiplier = power(base, exp>>1);
if (exp & 1)
return multiplier * multiplier * base;
return multiplier * multiplier;
}
int main() {
long long n, p;
in >> n >> p;
out << power(n, p) << "\n";
return 0;
}
