function power
来源:互联网 发布:刺客信条2优化怎么样 编辑:程序博客网 时间:2024/06/04 19:41
power (迭代版)int power(int n){ int pow = 1; while(0 < n--) pow <<= 1; return pow;}
复杂度O(2r)(r为输入指数n的比特数)
power(递归)int power(int n){ return (1 > n) ? 1 : power(n - 1);}
复杂度O(2r)
int power(int n){ int pow = 1; int p = 2; while(n > 0) { if(n & 1) pow *= p; n >> 1; p *= p; } return pow;}
复杂度为O(logn)=O(r)
int power(int n){ int pow = 1; int p = a; while(n > 0) { if(n & 1) pow *= p; n >> 1; p *= p; } return pow;}
推广至an
inline int sqr(int a){return a*a};int power(int n){ if(0 == n)return 1; return (n & 1) ? sqr(power(n >> 1)) << 1: sqr(power(n >> 1));}
复杂度为O(logn)=O(r)
阅读全文
0 0
- function power
- ERROR: Power Handler function yield to low priority thread 解决办法
- ERROR: Power Handler function yield to low priority thread. 解决方法
- power
- power
- power
- Power
- Power
- power
- ERROR: Power Handler function yield to low priority thread 解决办法(作者:JNU_kinke)
- Write one line C function to find whether a no is power of two
- windows mobile 6.5.3 ERROR: Power Handler function yield to low priority thread.
- Given an integer, write a function to determine if it is a power of two.
- Given an integer, write a function to determine if it is a power of two
- PCI1320 Bus fatal error on bus 0 device3 function 2. power cycle system
- Function
- function
- function
- 十个值得一试的开源深度学习框架
- palindrome-partitioning Java code
- Android architecture component架构
- Numpy库学习——线性代数及相关运算
- C++中的引用和指针的区别
- function power
- @RequestMapping 用法详解之地址映射 含 参数绑定(@RequestParam、 @RequestBody、 @RequestHeader 、 @PathVariable)
- 习题3.2
- Android architecture component架构集成
- 战斗流程设计杂谈
- Linux的初体验
- 尽量避免双Key系统
- springcloud feign远程调用熔断详解
- 化身孤岛的鲸