Cod sursa(job #1552162)
Utilizator | Data | 17 decembrie 2015 12:20:53 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.35 kb |
#include <fstream>
using namespace std;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
long long n,p,x,i;
int main()
{
fin >> x >> n;
p=1;
while (n>0)
{
if (n%2!=0)
{
p=p*x;
n=n-1;
}
x=x*x;
n=n/2;
}
fout << p << endl;
return 0;
}