Cod sursa(job #1569788)
Utilizator | Arvat Ovidiu Daniel iDanyel | Data | 15 ianuarie 2016 22:00:43 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream f("lgput.in");
ofstream g("lgput.out");
int n, x;
long p;
p=1;
f >> x >> n;
while(n>0)
{
if(n%2!=0)
{
p*=x;
n--;
}
x*=x;
n=n/2;
}
g << p;
f.close();
g.close();
return 0;
}