HDU 4349(Lucas 變形)

hdu 4349
題目大意:
求組合數(n0)(n1)(nn) 中計算結果爲偶數的個數;
思路:已知(nm)(n>m) 爲奇數,當且僅當(nm)=m 時爲奇數;
(nm)(n2m2)(n%2m%2)(mod2) ,
又已知(01)=0 ,(11)=1 ,(10)=1 ,(00)=1 ,
即求取n中1的個數;

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int n;

    while (~scanf("%d", &n))
    {
        int cnt = 0;

        while (n)
        {
            if (n & 1)
            {
                cnt++;
            }

            n >>= 1;
        }

        printf("%d\n", (1 << cnt));
    }
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章