Cod sursa(job #2761837)
Utilizator | Data | 4 iulie 2021 12:16:38 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.35 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
int main()
{
int x, p, c=0;
in>>x>>p;
if(p%2==1)
c=x;
x*=x;
p/=2;
while(p>1)
{
x*=x;
p/=2;
}
if(c>0)
x*=c;
out<<x;
return 0;
}