An odd number of HDU 4349 combined number-Yang Hui triangle &lucas theorem

Source: Internet
Author: User

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

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.