Cod sursa(job #1914818)
| Utilizator | Data | 8 martie 2017 18:40:17 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.4 kb |
#include <bits/stdc++.h>
#define m 1999999973
#define ull unsigned long long
using namespace std;
ull ans,n,p;
int lgput(ull n, ull p){
ull ans=1;
if (p==0) return ans;
else if (p==1) return n;
else{
if (p%2==1) ans*=n*lgput(n*n,p/2);
else ans*=lgput(n*n,p/2);
return ans;
}
}
int main(){
cin>>n>>p;
cout<<lgput(n,p);
return 0;
}
