1 solutions

  • 0
    @ 2026-1-25 17:59:03

    看着道题没人过啊,我来发题解了:

    #include <iostream>
    using namespace std;
    
    int main() {
        long long a, b;
        cin >> a >> b;
    
        const long long LIMIT = 1000000000LL;
    
        // 特判 a == 1
        if (a == 1) {
            cout << 1 << endl;
            return 0;
        }
    
        // 如果 a > 1 且 b 很大,肯定超
        // 因为 2^30 > 1e9,所以 b > 60 肯定超(保险起见)
        if (b > 60) {
            cout << -1 << endl;
            return 0;
        }
    
        long long res = 1;
        for (int i = 0; i < b; ++i) {
            res *= a;
            if (res > LIMIT) {
                cout << -1 << endl;
                return 0;
            }
        }
    
        cout << res << endl;
        return 0;
    }
    • 1

    Information

    ID
    477
    Time
    500ms
    Memory
    128MiB
    Difficulty
    10
    Tags
    (None)
    # Submissions
    19
    Accepted
    1
    Uploaded By