Xiao Ming ' s Hope
Abstract: Ask for C (n,0), C (n,1),......, C (n,n) The number of odd numbers.
Idea: Investigate C (n,m)%2.
By Lucas theorem C (A, B) =c (a[n-1],b[n-1]) *c (a[n-2],b[n-2]) * ... *c (a[0],b[0]), where A[i] is a P-binary bit
To make C (n,m)%2==1, the corresponding bit on M can be 0,1 on the 1 bit on N, (c (1,0) =c () =1).
For bits 0 on n, the corresponding bit on M must be 0. (c (0,0) =1,c (0,1) =0).
So the title of the ans=2^cnt (CNT is n of the number of bits in 1).
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6 using namespacestd;7typedefLong LongLL;8 9 intMain ()Ten { One intN; A while(SCANF ("%d", &n)! =EOF) - { - intCnt=0; the while(n) - { - if(n&1) -cnt++; +N/=2; - } +printf"%d\n",1<<CNT); A } at return 0; -}
binomial coefficients
Topic abstraction: Judging the value of C (n,m)%2.
Idea: Lucas theorem. With M as the research object, for the 0 bits on the binary of M, there is no effect on singularity. Examine the 1 bits on the binary of M. For the result to be 1, the corresponding bit on n must be 1.
Ans= (n&m) ==m?1:0;
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6 using namespacestd;7typedefLong LongLL;8 9 intMain ()Ten { One intn,m; A while(SCANF ("%d%d", &n,&m)! =EOF) - { - if((n&m)! =m) theprintf"0\n"); - Else -printf"1\n"); - } + return 0; -}
Xiao Ming ' s Hope the generalization of Lucas theorem.