|
Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
|
Faster computation for \(a^b\). More...
#include <cassert>#include <cmath>#include <cstdint>#include <cstdlib>#include <ctime>#include <iostream>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.
| double fast_power_linear | ( | T | a, |
| T | b | ||
| ) |
Same algorithm with little different formula. It still calculates in \(O(\log N)\)
| double fast_power_recursive | ( | T | a, |
| T | b | ||
| ) |
algorithm implementation for \(a^b\)
| int main | ( | void | ) |
Main function