Cod sursa(job #2287760)
Utilizator | Data | 22 noiembrie 2018 14:48:59 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
double PutereLogaritmic(double x, int n)
{
double p = 1 ;
while (n > 0)
{
if (n & 1) // n este impar
{
p *= x;
n-- ;
}
x = x * x ;
n >>= 1 ; // sau n = n / 2
}
return p ;
}
int main(){
int n,p;
fin >> n >> p;
fout << PutereLogaritmic(n,p);
return 0;
}