Cod sursa(job #2044559)
Utilizator | Data | 21 octombrie 2017 11:04:35 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <fstream>
using namespace std;
int main()
{
ifstream f("lgput.in");
ofstream g("lgput.out");
long long n, p, rez=1;
f>>n>>p;
while(p>0)
{
if(p%2!=0)
{
rez*=n;
p--;
}
else
{
n*=n;
p/=2;
}
}
g<<rez;
return 0;
}