Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
74282 jdf25_wangchs 乘方计算 C++ 通过 0 MS 248 KB 711 2025-11-24 19:55:12

Tests(1/1):


#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; }


测评信息: