TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Faster computation for \(a^b\). More...
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <ctime>
#include <iostream>
Go to the source code of this file.
Functions | |
template<typename T > | |
double | fast_power_recursive (T a, T b) |
template<typename T > | |
double | fast_power_linear (T a, T b) |
int | main () |
Faster computation for \(a^b\).
Program that computes \(a^b\) in \(O(logN)\) time. It is based on formula that:
We can compute \(a^b\) recursively using above algorithm.
Definition in file fast_power.cpp.
double fast_power_linear | ( | T | a, |
T | b ) |
Same algorithm with little different formula. It still calculates in \(O(\log N)\)
Definition at line 50 of file fast_power.cpp.
double fast_power_recursive | ( | T | a, |
T | b ) |
algorithm implementation for \(a^b\)
Definition at line 26 of file fast_power.cpp.
int main | ( | void | ) |
Main function
Definition at line 68 of file fast_power.cpp.