HDU 4349 Xiao Ming's Hope [Lucas定理 二进制]

这种题面真是够了......@小明


题意:the number of odd numbers of C(n,0),C(n,1),C(n,2)...C(n,n).


 

奇数...就是mod 2=1啊

用Lucas定理,2的幂,就是二进制啊

${1\choose 1}={1\choose 0}={0\choose 0}=1 \quad {0\choose 1}=0$

只要二进制有1位n是0而i是1,${n\choose i}$就不是奇数啦

对于n二进制的每一个1,i都有两种选择,答案就是$2^{bitCount(n)}$

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
int n;
inline int bitCount(int n){
    int c=0;
    for(;n;++c) n&=(n-1);
    return c;
}
int main(){
    while(scanf("%d",&n)!=EOF){
        int bin=bitCount(n);
        printf("%d\n",1<<bin);
    }
}

 

posted @ 2017-02-15 20:54  Candy?  阅读(169)  评论(0编辑  收藏  举报