zoukankan      html  css  js  c++  java
  • xdoj-1057(Lucas定理的证明及其模板)

    Lucas定理的证明: 转自百度百科(感觉写的还不错)

    首先你需要这个算式:
      
    ,其中f > 0&& f < p,然后
    (1 + x) nΞ(1 + x) sp+q Ξ( (1 + x)p)s· (1 + x) q Ξ(1 + xps· (1 + x) q(mod p) 
      
      
    (modp)
    所以得(1 + x) sp+q 
     
    (mod p)
      
    我们求右边的
      
    的系数为:
    求左边的
      
    为:
    通过观察你会发现当且仅当i = t , j = r ,能够得到
      
    的系数,即
      
     
     
    所以
    得证。
     Lucas定理模板
     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstdio>
     4 typedef long long LL;
     5 const LL mod = 10007;
     6 LL fac[mod+10];
     7 LL n,m;
     8 LL q_pow (LL x,LL k) {
     9     LL ans=1;
    10     while (k) {
    11         if (k&1) ans=ans*x%mod;
    12         k=k>>1;
    13         x=x*x%mod;
    14     }
    15     return ans;
    16 }
    17 LL C (LL x,LL y) {
    18     if (y>x)  return 0;// 重要
    19     LL t1=fac[x];
    20     LL t2=fac[x-y]*fac[y]%mod;
    21     return t1*q_pow(t2,mod-2)%mod;
    22 }
    23 LL Lucas (LL x,LL y) {
    24     if (y==0) return 1;//递归出口
    25     return C (x%mod,y%mod)*Lucas (x/mod,y/mod)%mod;
    26 }
    27 int main ()
    28 {
    29     fac[0]=1;//一定不要忘了0
    30     for (int i=1;i<=mod;i++)
    31         fac[i]=fac[i-1]*i%mod;
    32     while (~scanf ("%lld %lld",&n,&m)) 
    33         printf ("%lld
    ",Lucas(m+n-1,n-1));// (多重集合取组合数)
    34     return 0;
    35 }
    抓住青春的尾巴。。。
  • 相关阅读:
    pkuwc2019自闭记
    一些多项式的整理
    Codeforces 1085G(1086E) Beautiful Matrix $dp$+树状数组
    Codeforces 1083C Max Mex 线段树
    Codeforces 1090J $kmp+hash+$二分
    Codeforces 1073G Yet Another LCP Problem $SA$+单调栈
    Codedforces 1076G Array Game 线段树
    LuoguP5017 摆渡车 $dp$
    NOIP2018游记
    解决python3 安装turtle的问题
  • 原文地址:https://www.cnblogs.com/xidian-mao/p/8514961.html
Copyright © 2011-2022 走看看