zoukankan      html  css  js  c++  java
  • Lucas模板

    #include <bits/stdc++.h>
    
    using namespace std;
    
    #define REP(i,n)        for(int i(0); i <  (n); ++i)
    #define rep(i,a,b)        for(int i(a); i <= (b); ++i)
    #define dec(i,a,b)        for(int i(a); i >= (b); --i)
    #define for_edge(i,x)        for(int i = H[x]; i; i = X[i])
    
    const int N    =    1000000        +    10;
    const int M    =    10000        +    10;
    const int Q    =    1000        +    10;
    const int A    =    30        +    1;
    
    typedef long long LL;
    
    
    LL fac[N];
    
    LL n, m, mod;
    
    inline LL Pow(LL a, LL b, int Mod){ LL ret(1); for (; b; b >>= 1, (a *= a) %= Mod) if (b & 1) (ret *= a) %= Mod; return ret;}    
    
    inline LL C(LL n, LL m){ return m > n ? 0 : fac[n] * Pow(fac[m] * fac[n - m] % mod, mod - 2, mod) % mod; }
    
    
    LL Lucas(LL n, LL m){ return m == 0 ? 1 : (C(n % mod, m % mod) % mod) * (Lucas(n / mod, m / mod) % mod) % mod;  }
    
    int main(){
    
        scanf("%lld %lld %lld", &n, &m, &mod);
        fac[0] = 1; rep(i, 1, N - 5) fac[i] = (fac[i - 1] * i) % mod;
        printf("%lld
    ", Lucas(n, m));
        
        return 0;
        
    }

    来自cxhscst2,(~ ̄▽ ̄)~

  • 相关阅读:
    动手动脑之异常处理
    git一些概念
    jquery each函数使用
    数据库客户端
    plotly.js
    网站跳转汇总
    jquery 实现间隔运行
    学习 在线调试
    Robot限制字典的key大写的class
    Gerrit 相关
  • 原文地址:https://www.cnblogs.com/stepping/p/7477645.html
Copyright © 2011-2022 走看看