Cod sursa(job #1515685)
Utilizator | Data | 2 noiembrie 2015 07:18:22 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
# include<cstdio>
using namespace std;
FILE *f=freopen("lgput.in","r",stdin);
FILE *g=freopen("lgput.out","w",stdout);
long long logputere( long long baza, int exp ){
if (exp == 0)
return 1LL;
else if ( exp % 2 == 0 )
return logputere( baza * baza, exp / 2 );
else
return logputere( baza * baza, exp / 2 ) * baza;
}
int main()
{
long long n,p,x;
scanf("%lld%lld",&n,&p);
x = logputere(n,p);
printf("%lld",x);
return 0;
}