Cod sursa(job #1804151)
Utilizator | Data | 12 noiembrie 2016 11:51:10 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <cstdio>
using namespace std;
long long n, p;
void putere()
{
long long tmp = 1;
while(p != 1)
{
if(p % 2 == 1)
{
tmp *= n;
}
n *= n;
p /= 2;
}
printf("%lld",n * tmp);
}
void citire()
{
scanf("%d %d",&n,&p);
putere();
}
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
citire();
return 0;
}