提交时间:2025-11-24 19:55:12

运行 ID: 74282

#include <iostream> #include <cmath> using namespace std; int main() { int a, n; cin >> a >> n; if (a == 0) { cout << 0 << endl; return 0; } if (a == 1) { cout << 1 << endl; return 0; } if (a == -1) { cout << (n % 2 == 0 ? 1 : -1) << endl; return 0; } long long result = 1; for (int i = 0; i < n; i++) { result *= a; if (abs(result) > 1000000) { // 题目保证不会超过,所以这里理论上不会执行 // 但如果真的超过,直接退出循环 break; } } cout << result << endl; return 0; }