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的幂,就是二进制啊

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

只要二进制有1位n是0而i是1,${nchoose 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
",1<<bin);
    }
}
原文地址:https://www.cnblogs.com/candy99/p/6403347.html