求助J t1 90pts
  • 板块学术版
  • 楼主star_maelstorm
  • 当前回复2
  • 已保存回复2
  • 发布时间2022/10/29 20:47
  • 上次更新2023/10/27 05:04:12
查看原帖
求助J t1 90pts
602527
star_maelstorm楼主2022/10/29 20:47
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
ull maxn=pow(2,31)-1;
ull n,m;
ull ksm(ull a,ull b)
{
	ull ans=1;
	while(b)
	{
		if(b&1) ans=ans*a;
		b>>=1;
		a=a*a;
	}
	return ans;
}
int main()
{
	//freopen("pow.in","r",stdin);
	//freopen("pow.out","w",stdout);
	cin>>n>>m;
    if(n==1)
    {
        cout<<1<<endl;
        return 0;
    }
	if(ksm(n,m)>maxn) cout<<-1<<endl;
	else cout<<ksm(n,m);
	return 0;
}

RT 评测

2022/10/29 20:47
加载中...