TLE on #7,#8
查看原帖
TLE on #7,#8
560044
wangyi_c楼主2022/10/29 22:28
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m;
int max_ans=1e9;
int qpow(int a,int b){
	if(b==1) return a;
	if(b==0) return 1;
	if(b%2==0){
		int x=qpow(a,b/2)*qpow(a,b/2);
		if(x>max_ans){
			cout<<-1;
			exit(0);
		}
		return x;
	}
	int x=a*qpow(a,b/2)*qpow(a,b/2);
	if(x>max_ans){
		cout<<-1;
		exit(0);
	}
	return x;
}
signed main(){
	freopen("pow.in","r",stdin);
	freopen("pow.out","w",stdout);
	cin>>n>>m;
	cout<<qpow(n,m);
	return 0;
}
2022/10/29 22:28
加载中...