为什么官网90分,但洛谷可以AC
查看原帖
为什么官网90分,但洛谷可以AC
545083
123XTY123楼主2022/11/10 16:29
#include<bits/stdc++.h>
//#define int long long
using namespace std;
void read(int &x){
	int w=1,c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') w=-1;
		c=getchar();
	}
	x=c-48;
	c=getchar();
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-48;
		c=getchar();
	}
	x=x*w;
}
long long a,b;
long long ksm(long long x,long long y){
	long long ans=1;
	while(y){
		if(y&1){
			if(ans*x>1000000000){
				cout<<-1;
				exit(0);
			}
			ans=ans*x;
		}
		y=y>>1;
		x=x*x;
		if(y!=0&&x>1000000000){
			cout<<-1;
			exit(0);
		}
	}
	return ans;
}
int main(){
//	freopen("pow.in","r",stdin);
//	freopen("pow.out","w",stdout);
	cin>>a>>b;
	cout<<ksm(a,b);
	return 0;
}
2022/11/10 16:29
加载中...