Cod sursa(job #1956078)
Utilizator | Data | 6 aprilie 2017 14:41:48 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.33 kb |
#include <iostream>
#include <fstream>
using namespace std;
int n,p;
int main()
{freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
scanf("%d%d", &n, &p);
long long x=1;
while(p>0)
{
if(p%2==1)
{
x*=n;
p--;
}
n=n*n;
p=p/2;
}
printf("%lld", x);
return 0;
}