Lucas theorem: N is written in P-ary A[n]a[n-1]a[n-2]...a[0], and M is written in P-b[n]b[n-1]b[n-2]...b[0], then C (n,m) and C (A[n],b[n]) *c (a[n-1],b[n-1]) *c ( A[n-2],b[-2]) *....*c (a[0],b[0]) modulo p congruence.
namely: Lucas (n,m,p) =c (n%p,m%p) *lucas (n/p,m/p,p)
The problem is C (n,0), C (n,1), C (n,2) ... C (n,n). How many of them are odd
It also means that the range of the number m of the C (n,m)%2==1 is 0-n
C (n,m)%2, then by Lucas theorem, we can write binary form of observation
For example, n=010 M is 000 001 010
The end result is 1+0+1=2
Because C (0,1) =0
So C (0,0) * C (1,0) *c (0,1) = 0
So the 0 in n = 010 does not correspond to the 1 in M, otherwise it will
n = 1 in 010 can correspond to the 0 or 1 in m
It becomes the number of 1 in the binary that asks for N. 1
The final result is 2^ (number of 1 in N)
Sample Input
1//n
2
11
Sample Output
2
2
8
1# include <iostream>2# include <cstdio>3# include <cstring>4# include <algorithm>5# include <string>6# include <cmath>7# include <queue>8# include <list>9# define LLLong LongTen using namespacestd; One A - intMain () - { the //freopen ("In.txt", "R", stdin); - intN; - while(SCANF ("%d", &n)! =EOF) - { + intCnt=0; - while(n) + { A if(n&1) atcnt++; -n>>=1; - } -printf"%d\n",1<<CNT); - } - return 0; in}
View Code
HDU 4349 C (n,0), C (n,1), C (n,2) ... C (n,n). How many odd numbers are there (Lucas theorem generalization)