我的快速幂何以出锅?
查看原帖
我的快速幂何以出锅?
112917
Eason_AC楼主2020/11/21 14:31

RT,输入样例之后半天输出不出来,我甚至直接蒯了模板的代码都半天不输出,洛谷 IDE 显示超过时间限制,有大佬来帮忙看看的吗?qwq

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;

const long long mod = 2000000011;

long long quickPow(long long a, long long b, long long k) {
	if(k == 1)	return 0; 
	long long ans = 1;
	while(b) {
		if(b & 1)	ans = ans * a % k;
		a = a * a % k;
		b >>= 1;
	}
	return ans;
}

int main() {
	int t; scanf("%d", &t);
	for(int kase = 1; kase <= t; ++kase) {
		long long x; scanf("%lld", &x);
		printf("Case #%d: ", kase);
		printf("%lld\n", quickPow(x, x - 2, mod));
	}
	return 0;
}

2020/11/21 14:31
加载中...