排列组合

#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
const int mod = 1e9+7;
long long int N[100005];//n!打表
long long int a[100005];
void init()
{
    N[0] = N[1] = 1;
    for (int i=2; i<=100000; i++)
    {
        N[i] = (N[i-1]*i)%mod;
    }
}
long long gcd(long long x, long long y)
{
    if(y == 0)
    {
        return x;
    }
    return gcd(y, x% y);
}
void exgcd(long long a, long long b, long long &x, long long &y)//long long &gcd
{
    if(b == 0)
    {
        x= 1;
        y= 0;
        return;
    }
    exgcd(b, a% b, x, y);
    long long t= x;
    x= y;
    y= t- a/ b* y;
    return;
}
long long C(long long n, long long m)
{
    long long x1, y1, x2, y2;
    exgcd(N[n-m], mod, x1, y1);
    exgcd(N[m], mod, x2, y2);
    x1=(x1+mod)%mod;
    x2=(x2+mod)%mod;
    return ((N[n]*x1)%mod*x2)%mod;
}

卢卡斯定理

/* Cn下m上 p范围<1e5且需是素数 */  
class Lucas{  
    long quickmod(long a,long b,long p){    
        long res = 1;    
        while(b!=0){    
        if(b%2!=0) res = (res*a)%p;    
        a = (a*a)%p;    
        b /=2;    
    }    
        return res;    
    }    
    long Comb(long a,long b, long p){    
       if(a < b) return 0;    
       if(a == b) return 1;    
       if(b > a-b) b = a-b;    
       long ans = 1, ca = 1, cb = 1;    
       for(long i=0; i<b; ++i){    
        ca = (ca*(a-i))%p;    
        cb = (cb*(b-i))%p;    
       }    
       ans = (ca*quickmod(cb, p-2, p))%p;    
       return ans;    
    }    
    long Lucas(int n, int m, int p){    
        long ans = 1;    
        while(n!=0 && m!=0 && ans!=0){    
            ans = (ans * Comb(n%p, m%p, p))%p;    
            n /= p;    
            m /= p;    
        }    
        return ans;    
    }    
}

求n阶的近似值(斯特灵公式)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值