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