1 条题解

  • 0
    @ 2025-11-30 16:28:08

    C++ :

    #include <iostream>
    using namespace std;
    
    // 函数: 判断一个整数是否为2的幂
    bool isPowerOfTwo(int n) {
        return (n > 0) && (n & (n - 1)) == 0;
    }
    
    int main() {
        int n;
        cin >> n; // 读取输入
        if (isPowerOfTwo(n)) {
            cout << n << " is a power of two." << endl; 
        } else {
            cout << n << " is not a power of two." << endl;
        }
        return 0;
    }
    
    
    
    
    
    • 1

    信息

    ID
    1486
    时间
    2000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者