1011_Xiao_Ming’s_Hope

來源:互聯網
上載者:User

題目:

hdu_4349_Xiao_Ming's_Hope

 

官方題解:本題為Lucas定理推導題,我們分析一下 C(n,m)%2,那麼由lucas定理,我們可以寫成二進位的形式觀察,比如 n=1001101,m是從000000到1001101的枚舉,我們知道在該定理中C(0,1)=0,因此如果n=1001101的0對應位置的m二進位位為1那麼C(n,m) % 2==0,因此m對應n為0的位置只能填0,而1的位置填0,填1都1(C(1,0)=C(1,1)=1),不影響結果為奇數,並且保證不會出n的範圍,因此所有的情況即是n中1位置對應m位置0,1的枚舉,那麼結果很明顯就是:2^(n中1的個數)

 

個人理解:正如題解所說,本題是Lucas定理的直接應用。當然也可以多寫幾個答案,看出答案與N的關係是2^(n中1的個數)。  Lucas定理:     

For non-negative integers m and n and a prime p, the following congruence relation holds:



where



and



are the base p expansions of m and n respectively.

定理還不會證。

 

標程:
#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>using namespace std;int lowbit(int x) {    return x & (-x);}int get_result(int n) {    int res = 0;    while (n) {        n -= lowbit(n);        res++;    }    return res;}int main() { //   freopen("data.in", "r", stdin); //   freopen("data.out", "w", stdout);    int n;    while (scanf("%d", &n) != EOF) {        printf("%d\n", 1 << get_result(n));    }    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.