// // Created by aurora on 24-8-14. // #include #include bool isPowerOfTwo(int n) { if (n <= 0) return false; while (n / 2) { if (n % 2 != 0) return false; n /= 2; } return true; } int main() { assert(isPowerOfTwo(2) == true); assert(isPowerOfTwo(0) == false); assert(isPowerOfTwo(1) == true); }