Cod sursa(job #1650030)
Utilizator | Data | 11 martie 2016 16:14:30 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
inline int Put_Log(long long x,long long n)
{
if(n==1)
return x;
if(n==0)
return 1;
if(n&1)
return 1LL*Put_Log(x,n-1);
x=Put_Log(x,n/2);
return 1LL*x*x;
}
int main()
{
long long n,p;
f>>n>>p;
g<<Put_Log(n,p)<<"\n";
return 0;
}