Cod sursa(job #2351919)
| Utilizator | Data | 22 februarie 2019 20:11:04 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int pow(int x, int y) {
int a = x, b = y;
int p = 1;
while (b != 1) {
if (b % 2 == 0) {
p *= a * a;
} else {
p *= a * a * a;
}
b /= 2;
}
return p;
}
int main()
{
int a, b;
fin >> a >> b;
fout << pow(a, b);
return 0;
}
