虽然AC了,但自己写的代码确实有点丑陋(呜呜呜呜呜)
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
LL a, b;
int main()
{
scanf("%lld%lld", &a, &b);
if (a == 1)
{
printf("1\n");
return 0;
}
LL res = 1;
for (int i = 0; i < b; ++ i)
{
res *= a;
if (res > 1e9)
{
res = -1;
break;
}
}
printf("%lld", res);
return 0;
}
来看一份优雅的代码hh^_^
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
LL a, b;
int main()
{
scanf("%lld%lld", &a, &b);
LL res = 1;
while (a > 1 && b --)
{
res *= a;
if (res > 1e9)
{
res = -1;
break;
}
}
printf("%lld\n", res);
return 0;
}