你谷样例是不是不负责
  • 板块灌水区
  • 楼主Aya_Cx330
  • 当前回复6
  • 已保存回复6
  • 发布时间2022/10/29 16:12
  • 上次更新2023/10/27 05:09:45
查看原帖
你谷样例是不是不负责
494994
Aya_Cx330楼主2022/10/29 16:12

赛事 T1 我用快速幂:

#include<bits/stdc++.h>
using namespace std;
const long long ttt=31622;
long long Pow(long long a,long long b)
{
	long long ret=a,sum=1;
	while(b!=1)
	{
		if(b%2==0)
		{
			if(ret>ttt) return -1;
			ret*=ret;
			b/=2;
		}
		else
		{
			sum*=ret;
			b--;
		}
	}
	if(sum*ret>1e9||sum*ret<-1) return -1;
	return sum*ret;
}
int main()
{
	long long a,b;
	scanf("%lld%lld",&a,&b);
	cout<<Pow(a,b);
	return 0;
}

可是这样也能过洛谷自测耶:

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(pow(a,b)>1e9)
	{
		cout<<-1;
	}
	else
	{
		cout<<(int)pow(a,b);
	}
	return 0;
}

2022/10/29 16:12
加载中...