BZOJ3209:花神的数论题(数位dp)

题面
题意:s(n)为n的二进制1的个数。
求s的前缀积,n≤1e15

即对于每个i
求小于等于n的数中
二进制有i个1的有几个

大概就一个数位dp了

#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
#define mmst(a, b) memset(a, b, sizeof(a))
#define mmcp(a, b) memcpy(a, b, sizeof(b))

typedef long long LL;

const int N=110;
const LL mo=10000007;

LL f[N][N],g[N][N];
LL n,ans=1;

LL cheng(LL a,LL b)
{
    LL res=1;
    for(;b;b>>=1,a=a*a%mo)
    if(b&1)
    res=res*a%mo;
    return res;
}

int main()
{
    cin>>n;

    f[51][0]=1;
    for(LL i=50;i>=0;i--)
    for(int j=0;j<=50;j++)
    {
        if((n&(1ll<<i))==0)
        {
            f[i][j]=f[i+1][j];
            g[i][j]=g[i+1][j]+g[i+1][j-1];
        }
        else
        {
            f[i][j]=f[i+1][j-1];
            g[i][j]+=g[i+1][j]+f[i+1][j]+g[i+1][j-1];
        }
    }

    for(int i=2;i<=50;i++)
    ans=ans*cheng(i,f[0][i]+g[0][i])%mo;

    cout<<ans<<endl;

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值