#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阶的近似值(斯特灵公式)