Files
python/TangDou/CSP-J/J2-2022/pow.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

26 lines
620 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main() {
freopen("pow.in", "r", stdin);
freopen("pow.out", "w", stdout);
LL a, b, res = 1;
cin >> a >> b;
//需要对a==1进行特判,否则肯定会TLE一个点,为啥呢?因为b的范围!它是<=1e9!如果a是1,会空跑1e9次!
if (a == 1) {
printf("%d\n", 1);
exit(0);
}
for (LL i = 1; i <= b; i++) {
res *= a;
if (res > 1e9) {
printf("%d\n", -1);
exit(0);
}
}
printf("%lld\n", res);
return 0;
}