• Dyt's math [数学, 推式子]


    Dyts mathDyt's math

    , 998244353 :求解下式,对 998244353 取模:

    i=1nCikbisum_{i=1}^n C_i^k b^i

    k5×105,n1018,2b998244353.k le 5 imes 10^5, n le 10^{18},2 le b le 998244353.


    color{red}{正解部分}

    Fk=i=1nCikbiF_k = sumlimits_{i=1}^n C_i^k b^i, 则 Fk1=i=1nCik1biF_{k-1} = sumlimits_{i=1}^n C_i^{k-1} b^i,

    bFk1=i=2n+1Ci1k1bibF_{k-1} = sumlimits_{i=2}^{n+1} C_{i-1}^{k-1} b^i,

    bFk=i=2n+1Ci1kbibF_k = sumlimits_{i=2}^{n+1} C_{i-1}^k b^i,

    bFk1+bFk=i=2n+1(Ci1k+Ci1k1)bi=i=2n+1Cikbi=Fk+Cn+1kbn+1C1kb herefore bF_{k-1}+bF_k = sumlimits_{i=2}^{n+1}left(C_{i-1}^k +C_{i-1}^{k-1} ight) b^i = sumlimits_{i=2}^{n+1}C_i^k b^i = F_k + C_{n+1}^kb^{n+1}-C_1^kb .

    Fk=bFk1Cn+1kbn+1+C1kb1b herefore F_k = frac{bF_{k-1}-C_{n+1}^kb^{n+1}+C_1^kb}{1-b}

    F0=i=1nbi=b(1bn)1b又ecause F_0 = sum_{i=1}^n b^i = frac{b(1-b^n)}{1-b}

    所以可以 O(K)O(K) 得到 FkF_k .


    color{red}{实现部分}

    #include<bits/stdc++.h>
    #define reg register
    typedef long long ll;
    
    const int maxn = 500005;
    const int mod = 998244353;
    
    int K;
    int B;
    
    ll N;
    
    int Ksm(int a, ll b){int s=1;while(b){if(b&1)s=1ll*s*a%mod;a=1ll*a*a%mod;b>>=1;}return s;}
    
    int main(){
            scanf("%lld%d%d", &N, &B, &K);
            int inv_b = Ksm(B-1, mod-2);
            int Ans = 1ll*B*(Ksm(B, N)-1)%mod*inv_b % mod;
            int C = (N + 1)%mod;
            for(reg int i = 1; i <= K; i ++){
                    int C1kb = (i==1)*B;
                    Ans = -1ll*B*Ans % mod;
                    Ans += 1ll*C*Ksm(B, N+1)%mod;
                    Ans -= C1kb;
                    Ans %= mod, Ans += mod, Ans %= mod;
                    Ans = 1ll*Ans*inv_b % mod;
                    C = (N-i+1)%mod*C%mod*Ksm(i+1, mod-2)%mod;
            }
            printf("%d
    ", Ans);
            return 0;
    }
    
    
  • 相关阅读:
    我的Java学习路线图
    请求重定向和请求转发的区别
    PHP代码审计学习-php安全基础
    无密码正向直连内网linux目标机复现
    Windows API 学习
    Http请求走私
    免杀手法-tcp套字节传递shellcode学习
    自启动模块构造-计划任务
    自启动模块构造-快速启动目录
    进程注入免杀学习
  • 原文地址:https://www.cnblogs.com/zbr162/p/11822477.html
Copyright © 2020-2023  润新知