Cod sursa(job #1944335)
Utilizator | Data | 29 martie 2017 08:51:37 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long x;
int n;
long long P(long long x,int n)
{
double a;
if(n==0) return 1;
if(n==1) return x;
else
{
a=P(x,n/2);
if(n%2==1) return a*a*x;
else return a*a;
}
}
int main()
{
f>>x>>n;
f<< P(x,n)<< endl;
return 0;
}