STL 中的 power 函数实现

计算x的n次幂最简单直接的方法就是相乘n次,很容易写出程序:windows //计算x^n 直接乘n次 int power1(int x, unsigned int n) { int result = 1; while(n--) { result *= x; } return result; }   这种计算的效率显然不高,咱们能够用二分法来加速计算x^n=x^(n/2)* x^(
相关文章
相关标签/搜索