Cod sursa(job #1571468)
Utilizator | Data | 18 ianuarie 2016 09:39:19 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <bits/stdc++.h>
using namespace std;
int n,p,z;
inline int solutie(unsigned long long x, unsigned long long y)
{
if(y==1) return x*1;
if(y==0) return 1;
if(x==1) return 1;
if(y%2==0) return solutie(x*x,y/2);
return x*solutie(x*x,(y-1)/2);
}
int main()
{
ifstream fin("lgput.in");
ofstream fout("lgput.out");
fin>>n>>p;
fout<<solutie(n,p);
fout.close();
fin.close();
return 0;
}