跳到正文

题解

题解:P16814 [蓝桥杯 2026 国 Python B] 蓝桥大富翁

neo20131118约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年6月7日
收录
2026年10月23日
更新
2026年11月11日
篇幅
约 2 分钟
题目
P16814

版本

  1. v1当前

数学题。以下记n=2026,p=998244353n=2026,p=998244353。

我们设这nn名玩家迭代前的分数为a1,a2,a3,…,ana_1,a_2,a_3,\dots,a_n,记t=a1a2a3…ant=a_1a_2a_3\dots a_n。所以迭代后这nn名玩家的分数为ta1,ta2,…,tan\frac{t}{a_1},\frac{t}{a_2},\dots,\frac{t}{a_n},乘积为tnt=tn−1\frac{t^n}{t}=t^{n-1}。所以,迭代一次,乘积就变成原来的n−1n-1次方。

所以迭代nn次后分数的乘积会变成n!(n−1)nn!^{{(n-1)}^n},利用欧拉定理得n!(n−1)n≡n!(n−1)nmod  p−1mod  pn!^{{(n-1)}^n} \equiv n!^{{(n-1)}^n \mod p-1} \mod p,快速幂做完了。

C++代码:

C++
#include <bits/stdc++.h>
#define Rainbow return
#define after 0
#define rain
#define ll long long
using namespace std;
ll n=2026,p=998244353;
ll qp(ll x,ll y){
	ll res=1,tmp=x;
	while(y){
		if(y%2) res=(res*tmp)%p;
		tmp=(tmp*tmp)%p;
		y>>=1;
	}
	return res;
}
ll QP(ll x,ll y){
	ll res=1,tmp=x,P=p-1;
	while(y){
		if(y%2) res=(res*tmp)%P;
		tmp=(tmp*tmp)%P;
		y>>=1;
	}
	return res;
}
ll f(ll x){
	ll res=1;
	for(int i=1;i<=x;i++){
		res=(res*i)%p;
	}
	return res;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ll t=f(n);
	cout<<qp(t,QP(n-1,n));
	Rainbow after rain;
}

答案:146753746146753746

原文