• LUCAS 定理


    原来一张图就就能证明:C(N,M)%P,p是素数。

    简直太炫酷

    先膜拜会

    #include<iostream>
    #include<cstdio>
    #include<ctime>
    #include<cstring>
    #include<cstdlib>
    #include<vector>
    #define C 240
    #define TIME 10
    #define LL long long
    using namespace std;
    LL PowMod(LL a,LL b,LL MOD){
    LL ret=1;
    while(b){
    if(b&1) ret=(ret*a)%MOD;
    a=(a*a)%MOD;
    b>>=1;
    }
    return ret;
    }
    LL fac[100005];
    LL Get_Fact(LL p){
    fac[0]=1;
    for(int i=1;i<=p;i++)
    fac[i]=(fac[i-1]*i)%p;
    }
    LL Lucas(LL n,LL m,LL p){
    LL ret=1;
    while(n&&m){
    LL a=n%p,b=m%p;
    if(a<b) return 0;
    ret=(ret*fac[a]*PowMod(fac[b]*fac[a-b]%p,p-2,p))%p;
    n/=p;
    m/=p;
    }
    return ret;
    }
    int main(){
    int t;
    scanf("%d",&t);
    while(t--){
    LL n,m,p;
    scanf("%I64d%I64d%I64d",&n,&m,&p);
    Get_Fact(p);
    printf("%I64d ",Lucas(n+m,m,p));
    }
    return 0;
    }

     模板

    http://blog.csdn.net/acdreamers/article/details/8220787 解释逆元的解法

  • 相关阅读:
    期待Eclipse3.4
    Winforms中使用系统托盘图标
    Eclipse下的Struts2开发插件
    彩色 夺冠
    网络&系统
    A Famous Music Composer
    Quick Brown Fox
    解密QQ号——队列
    谁先倒
    bootstrap Table从零开始
  • 原文地址:https://www.cnblogs.com/forgot93/p/4190856.html
Copyright © 2020-2023  润新知