Cod sursa(job #1382563)
Utilizator | Data | 9 martie 2015 11:22:42 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <cstdio>
#include <algorithm>
using namespace std;
#define N 1999999973
int p,n;
int lgp(int p)
{
if(p==0) return 1;
if(p%2==1)
return n*lgp(p-1);
int x=lgp(p/2);
return x*x;
}
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%d%d",&n,&p);
printf("%d\n",lgp(p));
return 0;
}