Cod sursa(job #2108829)
Utilizator | Data | 18 ianuarie 2018 20:52:26 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <iostream>
#include <iomanip>
using namespace std;
double expo(int x, int n){
double p =1;
while(n){
if(n%2==1)
{
p*=x;
n--;
}
x*=x;
n/=2;
}
return p;
}
double expoFor(int x, int n){
double p=1;
for(int i=0; i<n; i++)
p*=x;
return p;
}
int main(){
cout<<fixed<<expo(3, 13)<<endl;
cout<<expoFor(2, 45);
return 0;
}