Problem description when he was still a freshman in the cold moon, he found the magic binary number in a martial arts secret book (according to the research, it is estimated that it is a computer base, crazy sweat-ing.
If a positive integer m is binary, its number of digits is n (excluding leading 0), and the cold month is called N binary. In all the N binary numbers, the total number of 1 is called the number of months corresponding to n.
For example, there are four three binary numbers: 4 (100), 5 (101), 6 (110), and 7 (111 ), among them, the number of 1 is 1 + 2 + 2 + 3 = 8, so the number of months corresponding to 3 is 8. Input gives you an integer T, indicating the number of groups of input data, followed by T rows, each line contains a positive integer N (1 <= n <= 20 ). For each n, output the number of months corresponding to N in a row. Sample input3123 sample output138
1 #include <stdio.h> 2 #include <math.h> 3 4 int main(){ 5 int T; 6 int number; 7 double result; 8 double temp; 9 10 scanf("%d",&T);11 12 while(T--){13 scanf("%d",&number);14 temp=pow(2.0,(number-1));15 16 result=(temp+(temp/2*(number-1)));17 18 printf("%.0lf\n",result);19 } 20 return 0;21 }
Number of months