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;}