HDU 4349 C (n,0), C (n,1), C (n,2) ... C (n,n). How many odd numbers are there (Lucas theorem generalization)

Source: Internet
Author: User

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)

Related Article

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.