Cod sursa(job #1917677)
Utilizator | Data | 9 martie 2017 12:45:55 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int main()
{
long long x, y, r = 1;
fin>>x>>y; // calculam x la puterea y
while(y) {
if (y&1) {
r = r * x;
}
y = y >> 1;
x = x * x;
}
fout<<r;
fin.close();
fout.close();
return 0;
}