求助,CSP-J第一题用位运算为什么错了
  • 板块灌水区
  • 楼主Zero_fallen
  • 当前回复11
  • 已保存回复11
  • 发布时间2022/11/1 18:50
  • 上次更新2023/10/27 04:36:10
查看原帖
求助,CSP-J第一题用位运算为什么错了
716396
Zero_fallen楼主2022/11/1 18:50
#include	<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b;
	long long ans=1;
	scanf("%lld %lld",&a,&b);
	for(; b;b>>=1){
		if(b&1) ans*=a;
		a*=a;
		if(ans>1e9){
			printf("-1");
			return 0;
		}
	}
	printf("%lld",ans);
	return 0;
}
2022/11/1 18:50
加载中...