24pts求调,不知哪戳
查看原帖
24pts求调,不知哪戳
681558
Weizhuo_Zhao楼主2024/5/18 22:22
#include <bits/stdc++.h>
using namespace std;

int main() {
	long long a, b, p;
	cin >> a >> b >> p;
	cout << a << '^' << b << " mod " << p << '=';
	if (p == 1) {
		cout << 0;
		return 0;
	}
	int r = 1; //result
	while (b != 0) {
		if (b & 1 == 1) //b mod 2
			r = r*a%p;
		a = a * a;
		b = b >> 1; //floor(b / 2)
	}
	cout << r % p;
	return 0;
}
2024/5/18 22:22
加载中...