60 分(用了算法)
查看原帖
60 分(用了算法)
1407701
Luo_Yicheng楼主2024/12/16 22:34
#include <bits/stdc++.h>
#define int long long
using namespace std;

int a, b, p;

int fast_pow(int x, int y){
	if (y == 1)
		return x;
	if (y % 2 == 1)
		return (fast_pow(x, y / 2) % p * fast_pow(x, y / 2) % p) * x % p;
	else
		return (fast_pow(x, y / 2) % p * fast_pow(x, y / 2) % p) % p;
}

main(){
	cin >> a >> b >> p;
	cout << a << '^' << b << " mod " << p << '=' << fast_pow(a, b);
	return 0;
}
2024/12/16 22:34
加载中...