BZOJ 3209

来自我的新博客

BZOJ 3209

Description:

       令函数 f(x) 表示 x 在二进制表示下 1 的个数。求 Ni=1f(i) 10000007 取模的答案。

      
      
      

Solution:

       很简单的一道数位 dp 题,首先递推出组合数,然后逐位 dp 即可,由于比较简单就不具体解释了。

       细节:快速幂的时候不要对指数取模,如果你实在想要取模也可以,把指数对 φ(10000007) 取模。但是 10000007 不是质数,事实上 φ(10000007)=9988440
      
      
      

Code:

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

using namespace std;

long long N;
const long long Mod=10000007;
int to2[100]={0};
long long C[70][70]={{0}};

long long power(long long a,long long k)
{
    long long o=1;
    for(;k>0;k>>=1)
    {
        if(k&1) o=o*a%Mod;
        a=a*a%Mod;
    }
    return o;
}

int main()
{
    cin>>N;
    int tp=0;
    for(;N>0;N>>=1)
        to2[++tp]=(N&1);
    int count=0;
    C[0][0]=1;
    for(int i=1;i<=65;i++)
    {
        C[i][0]=1;
        for(int j=1;j<=65;j++)
            C[i][j]=C[i-1][j-1]+C[i-1][j];
    }
    long long ans=1;
    for(;tp>0;tp--)
    {
        if(to2[tp]==1)
        {
            for(int i=(count==0);i<=tp-1;i++)
                ans=ans*power(count+i,C[tp-1][i])%Mod;
        }
        count+=(to2[tp]==1);
    }
    cout<<ans*count%Mod<<endl;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值