超限后会变负数,可以以此作为判断条件
2025-07-17 21:32:11
发布于:上海
4阅读
0回复
0点赞
题解
#include<iostream>
using namespace std;
int a,b;
long long ans=1;
bool f=true;
int main()
{
cin>>a>>b;
while(b)
{
ans*=a;
if(ans<0)
{
f=false;
break;
}
b--;
}
if(ans<=1e9&&f)cout<<ans;
else cout<<-1;
}**加粗文本**
这里空空如也
有帮助,赞一个