HDU 4349 Xiao Ming ' s Hope,lucas theorem

Source: Internet
Author: User
Tags ming

Xiao Ming ' s Hope Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1793 Accepted Submission (s): 1189


Problem Description Xiao Ming likes counting numbers very much, especially he is fond of counting odd numbers. Maybe he thinks it is the best-of-the-show he is alone without a girl friend. The day 2011.11.11 comes. Seeing classmates walking with their girl friends, he coundn ' t help running to he classroom, and then opened his maths Book preparing to count odd numbers. He looked at his book, then he found a question "C (n,0) +c (n,1) +c (n,2) +...+c (n,n) =?". Of course, Xiao Ming knew the answer, but he didn ' t care on that, what's he wanted to know is, how many odd numbers There were? Then he began to count odd numbers. When n was equal to 1, C (1,0) =c (=1), there was 2 odd numbers. When n was equal to 2, C (2,0) =c (2,2) =1, there was 2 odd numbers ... Suddenly, he found a girl was watching him counting odd numbers. In order to show his gifts on maths, he wrote several big numbers what n would is equal to, but he found it was impossible To finished him tasks, then he sent a piECE of information to you, and wanted your a excellent programmer to help him, he really didn ' t want to let she down. Can you help him?  
Input each line contains a integer n (1<=n<=10 8)
Output A single line with the number of odd numbers of C (n,0), C (n,1), C (n,2) ... C (N,n).
Sample Input

1 2 11
Sample Output
2 2 8
Author hit
Source multi-university Training Contest 5
http://blog.csdn.net/sky1203850702/article/details/7844035 Blog


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
int main () {
    long long n;
    while (cin>>n) {
        int res = 0;
        while (n) {
            if (n&1) res++;
            n/=2;
        }
        A long long ans = 1;
        for (int i = 0;i < res;i++)
            ans*=2;
        cout<<ans<<endl;
    }
    return 0;
}


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.