Xiao Ming ' s Hope the generalization of Lucas theorem.

Source: Internet
Author: User
Tags ming cmath

                       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.

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.