Test instructions: give you an n, ask C (n,0), C (n,1), C (n,2) ... C (n,n), number of odd numbers.
Analysis:
Lucas theorem:
A, B is a non-negative integer and P is a prime number. AB is written in P-system: a=a[n]a[n-1]...a[0],b=b[n]b[n-1]...b[0].
The combined number C (A, B) and C (A[n],b[n]) *c (a[n-1],b[n-1]) *...*c (a[0],b[0]) MODP congruence
namely: Lucas (n,m,p) =c (n%p,m%p) *lucas (n/p,m/p,p)
To see this problem, for odd, then we use binary, so a thought on the Open, C (n,m) =c (A[nk1],b[mk1]) *c (A[NK2][MK2]) * * * (mod 2), we know that C (0,1) is 0, so as long as the n bits on the 0 position, If m in this bit of the binary is 1, then C (n,m) modulo 2 is equal to 0, that is even, otherwise an odd number, and C (1,0), C () is 1, so n of the bits on the position of 1, M can fill the corresponding position 0 can also fill 1, which becomes a combinatorial problem, The bits with n has a total of K 1, so that C (n,m) is an odd m total of 2^k species.
It's a good way to do some questions that don't make a watch.
Code:
#include <iostream> #include <cstdio> #include <cmath>using namespace Std;int n;int main () {while ( scanf ("%d", &n)!=eof) {int tot=0;int j=n;int tmp=n&1; while (j) { if (TMP) tot++; j>>=1; tmp=j&1; } int Ans=pow (2,tot);p rintf ("%d\n", ans);}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
An odd number of HDU 4349 combined number-Yang Hui triangle &lucas theorem