Cod sursa(job #1276133)
Utilizator | Data | 25 noiembrie 2014 23:26:42 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int n , p;
double PutereLogaritmic(double x, int n)
{
double p = 1 ;
while (n > 0)
{
if (n % 2 ==1 )
{
p *= x;
n-- ;
}
x = x * x ;
n =n/2 ;
}
return p ;
}
int main()
{
fin>>n>>p;
fout<<PutereLogaritmic(n,p);
return 0;
}