HDU 4349 Xiao Ming's Hope(思路 lucas定理)

这里写图片描述
(图来自http://blog.csdn.net/acdreamers/article/details/8037918
首先我们知道 c(0,0)=1,c(0,1)=0,c(1,1)=1,c(1,0)=1
这个是基础。然后对于某个 c(n,m) 我们必须让右边的连乘式为1(模2的情况下,因为我们最终要求的也只是看他是不是奇数),所以对于连乘式中的每个 ni ,如果 ni 为0,那么 mi 一定是0,否则 c(n,m) 就为0了。而如果 ni 为1,那么 mi 可以是0,也可以是1,所以现在就相当于有n个选择,每个可以选0或1,这就是答案了。

#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<map>
#define inf 0x3f3f3f3f
typedef long long int lli;
using namespace std;
const lli mod = 1e12+7;

inline lli qp(lli a,lli x){
    lli ans = 1;a%=mod;
    for(;x;x>>=1){
        if(x&1) ans = ans*a%mod;
        a = a*a%mod;
    }
    return ans%mod;
}


int main(){
    lli t,n,m;
    while(~scanf("%lld",&n)){
        int cnt = 0;
        while(n){
            if(n&1)
                cnt++;
            n/=2;
        }
        printf("%lld\n",qp(2,cnt));
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值