Cod sursa(job #1660478)
| Utilizator | Data | 23 martie 2016 09:54:20 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.61 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream cin ("lgput.in");
ofstream cout ("lgput.out");
int x,y=1,puterea,numarul;
cin >> x >> puterea;
if (puterea=1)
numarul=x;
if (puterea=0)
numarul=1;
while (puterea>1)
{
if (puterea%2==0)
{
x=x*x;
puterea=puterea/2;
}
else
{
y=x*y;
x=x*x;
puterea=(puterea-1)/2;
}
}
numarul=x*y;
cout << numarul;
return 0;
}
