1011_xiao_ming's _ hope

Source: Internet
Author: User

Question:

Hdu_4349_xiao_ming's _ hope

 

Official question: In this article, we will give a rough analysis of C (n, m) % 2, so we can write the Lucas theorem into binary format for observation, such as N = 1001101, M is an enumeration from 000000 to 1001101. In this theorem, C () = 0, therefore, if the M binary bit of the corresponding position of 0 of N = 1001101 is 1, then C (n, m) % 2 = 0. Therefore, the position of M corresponding to N is 0 and only 0 can be entered, and fill in 0 in the position of 1, fill in 1 All 1 (C () = 1), do not affect the result is an odd number, and ensure that N is not out of the range, therefore, all the situations are the enumeration of 1 in N corresponding to 0, 1 in m, and the result is obviously: 2 ^ (number of 1 in N)

 

My personal understanding: As the question solves, this question is a direct application of the Lucas theorem. Of course, you can also write a few more answers to see that the relationship between the answer and N is 2 ^ (the number of 1 in N ). Lucas theorem:

For non-negative integersMAndNAnd a primeP, The following congruence relation holds:



Where



And



Are the basePExpansionsMAndNRespectively.

The theorem is not proven yet.

 

Bidding Process:
#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;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.