数学进位制相关模版

快速加模版

long long quickplus(long long  m,long long n,long long k)//返回m*n%k
{
    long long b = 0;
    while (n > 0)
    {
          if (n & 1)
             b = (b+m)%k;
          n = n >> 1 ;
          m = (m+m)%k;
    }
    return b;
}


快速幂取模模版:

typedef long long ll;
ll quickpow(ll a,ll b,ll c){
    int res=1;
    while(b>0){
        if(b&1)
            res=res*a%c;
        b=b>>1;
        a=(a%c)*(a%c)%c;
    }
    return res;
}


矩阵快速幂模版:

const int N=4; //矩阵维数
struct mat{
    int m[N][N];
    mat() {}
    mat unit(){   //单位矩阵 
        for(int i=0;i<N;i++)
            for(int j=0;j<N;j++)
                m[i][j]=i==j?1:0;
    }
};
mat t; //t为状态转移矩阵 
mat operator * (mat a,mat b){  //方阵乘法 
    mat res;
    for(int i=0;i<N;i++)
        for(int j=0;j<=N;j++){
            res.m[i][j]=0;
            for(int k=0;k<N;k++)
                res.m[i][j]+=(a.m[i][k]*b.m[k][j])%mod;
        }
    return res;
}
mat operator ^ (mat res,int n){ //方阵二分幂 
    res.unit();
    while(n>=1){
        if(n&1)
            res=res*t;
        n=n>>1;
        t=t*t;
    }
    return res;
}
void init(){ //初始化矩阵
} 


排列组合数模版:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+7;
const int mod = 1e9+7;
ll fac[maxn];
ll quickpow(ll a,ll b){ //快速幂
    int res=1;
    while(b>0){
        if(b&1)
            res=res*a%mod;
        b=b>>1;
        a=(a%mod)*(a%mod)%mod;
    }
    return res;
}
ll C(ll n,ll m)  //计算C(n,m)
{
    if(m>n||m<0)
        return 0;
    ll s1=fac[n],s2=fac[n-m]*fac[m]%mod;
    return s1*quickpow(s2,mod-2)%mod;
}
int main()
{
    fac[0]=1;             //预处理前缀
    for(int i=1;i<maxn;i++)
        fac[i]=fac[i-1]*i%mod;
    //printf("%lld\n",C(4,3));
}


统计二进制中有多少个1:

popcount(int x){
    return cnt[x>>16]+cnt[x&((1<<16)-1)];
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值