The number of hdu-2502-months

Source: Internet
Author: User

Topic links

http://acm.hdu.edu.cn/showproblem.php?pid=2502

Analysis:

For example, when n=4, there are:

1000 1001 1010 1011 1100 1101 1110 1111 you can see. Except for the first one. There are 000 001 010 011 100 101 110 111 can count, 0 and 1 of the total number half to half. So calculate the total number of 0 and 1, divided by 2 is good.

That is: 2^ (n-2) * (n-1)

Plus the first digit 1 total number: 2^ (n-1) The number of months

i.e. answer = 2^ (n-2) * (n-1) + 2^ (n-1)

Code

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main (void)
{
int t,n;
scanf ("%d", &t);
while (t--)
{
scanf ("%d", &n);
printf ("%.lf\n", pow (2,n-2) * (n-1) +pow (2,n-1));
}
return 0;
}

The number of hdu-2502-months

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.