关于T1
  • 板块学术版
  • 楼主Piggy343288
  • 当前回复15
  • 已保存回复15
  • 发布时间2022/10/29 13:50
  • 上次更新2023/10/27 05:11:31
查看原帖
关于T1
762646
Piggy343288楼主2022/10/29 13:50
#include<bits/stdc++.h>
#define int long long
using namespace std;
int qpow(int base,int p){
	int ans=1,tmp=base;
	while(p){
		if(p&1){
			if(1e9<ans*tmp)return -1;//乘完以后一定会爆1e9 
			ans*=tmp;
		}
		if(tmp>31622)return -1;//sqrt(1e9)
		tmp*=tmp;
		p>>=1;
	}
	return ans>1e9?-1:ans;
}

signed main(){
    int a,b;cin>>a>>b;
    if(a==1){
        cout<<1;
        return 0;
    }
    if(a>10&&b>=9){
		cout<<-1<<endl;return 0;
    }
    cout<<qpow(a,b)<<endl;
}

60pts,原因未知,求大佬解答

2022/10/29 13:50
加载中...