为什么快速幂只有60分呢
查看原帖
为什么快速幂只有60分呢
482312
BrainNotFound楼主2022/10/29 17:12
#include<bits/stdc++.h>
#define LL long long
using namespace std;

const int p = 1e9;

LL a,  b;
LL ksm(LL x, LL a){
	LL ans = 1;
	while(a){
		if(a & 1) ans *= x;
		a >>= 1;
		x *= x;
		if(x > p || ans > p) return -1;
	}
	return ans;
}

int main(){
	cin >> a >> b;
	cout << ksm(a, b) << endl;

	return 0;
}

rt

2022/10/29 17:12
加载中...