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