Cod sursa(job #2304277)
Utilizator | Data | 17 decembrie 2018 20:47:25 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.34 kb |
#include<fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int putere(long a,long b){
if(b==0)
return 1;
if(b&2==0)
return putere(a*a,b/2);
if(b&2==1)
return putere(a,b-1)*a;
}
int main(){
long N,P;
fin>>N>>P;
fout<<putere(N,P);
fin.close();
fout.close();
return 0;
}