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

· · 题解

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

我们设这n名玩家迭代前的分数为a_1,a_2,a_3,\dots,a_n,记t=a_1a_2a_3\dots a_n。所以迭代后这n名玩家的分数为\frac{t}{a_1},\frac{t}{a_2},\dots,\frac{t}{a_n},乘积为\frac{t^n}{t}=t^{n-1}。所以,迭代一次,乘积就变成原来的n-1次方。

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

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;
}

答案:146753746