Cod sursa(job #1009956)
Utilizator | Data | 14 octombrie 2013 00:45:00 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.36 kb |
#include <fstream>
using namespace std;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
int b, p, r=1;
int main()
{
fin>>b>>p;
while (p)
{
if (p%2==0)
{
b*=b;
p/=2;
}
else
{
p--;
r*=b;
}
}
fout<<r;
return 0;
}