• 【luogu3807】【bzoj2982】【模板】卢卡斯定理 combination


    P3807 【模板】卢卡斯定理

    bzoj2982  

    这两个题都是lucas的模板题 我只是因为combination的题面很有趣 所以决心一定要打出来

    证明什么的emmmmm 后面再说

    背模板!!!!

    LMZn个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样。那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案mod 10007的值。(1<=m<=n<=200,000,000)

    放combination的代码 这个体面hei因垂死听

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<queue>
     4 #include<cstring>
     5 #include<cmath>
     6 #include<stack>
     7 #include<algorithm>
     8 using namespace std;
     9 #define ll long long
    10 #define rg register
    11 ll p=10007;
    12 template <class t>void rd(t &x)
    13 {
    14     x=0;int w=0;char ch=0;
    15     while(!isdigit(ch)) w|=ch=='-',ch=getchar();
    16     while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    17     x=w?-x:x;
    18 }
    19 
    20 ll fpow(ll a,ll b)
    21 {
    22     ll res=1;
    23     while(b)
    24     {
    25         if(b&1) res=res*a%p;
    26         a=a*a%p,b>>=1;
    27     }
    28     return res;
    29 }
    30 
    31 ll C(ll n,ll m)
    32 {
    33     if(m>n) return 0;
    34     ll a=1,b=1;
    35     for(rg ll i=n-m+1;i<=n;++i) a=a*i%p;
    36     for(rg ll i=2;i<=m;++i) b=b*i%p;
    37     return (a*fpow(b,p-2))%p;
    38 }
    39 
    40 ll lucas(ll n,ll m)
    41 {
    42     if(!m) return 1;
    43     else return (C(n%p,m%p)*lucas(n/p,m/p))%p;
    44 }
    45 
    46 int main()
    47 {
    48     freopen("in.txt","r",stdin);
    49     //freopen("nocows.out","w",stdout);
    50     ll T;rd(T);
    51     while(T--)
    52     {
    53         ll n,m;
    54            rd(n),rd(m);
    55            printf("%lld
    ",lucas(n,m));
    56     }
    57     return 0;
    58 }
  • 相关阅读:
    八数码
    狂神说笔记——多线程05
    狂神说笔记——Java SE基础03
    从零开始的卷积神经网络
    深度学习与机器学习的区别
    模型的评估与选择
    经验风险VS风险函数
    常见的损失函数
    Erlang聊天室
    uniapp APP端 清除缓存
  • 原文地址:https://www.cnblogs.com/lxyyyy/p/10882925.html
Copyright © 2020-2023  润新知