幂
1.判断一个数是不是2的幂
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
bool isTwoPower(int n) { return (n > 0) && (n&(n - 1)); }
2.判断一个数是不是3的幂
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
class Solution { public: bool isPowerOfThree(int n) { if(n>0) { int maxThreePowerOfInt = pow(3,19); return maxThreePowerOfInt % n == 0?true:false; } return false; } };
3.一个数是不是4的幂
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
class Solution { public: bool isPowerOfFour(int num) { return (num>0)&&((num&(num-1))==0)&&((num&0x55555555)==num) ; } };