The meaning is to convert the decimal number to the binary number. The number of 0 is greater than or equal to 1. Given a closed interval, find the number of such ranges.
Description
The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone '(also known as 'Rock, Paper, Scissors', 'ro, sham, Bo', and a host of other names) in order to make arbitrary decisions such as who gets to be milked first. they can't even flip a coin because it's so hard to toss using hooves.
They have thus resorted to "round number" matching. the first cow picks an integer less than two billion. the second cow does the same. if the numbers are both "round numbers", the first cow wins,
Otherwise the second cow wins.
A positive integer N is said to be a "round number" if the binary representation of N has either or more zeroes than it has ones. for example, the integer 9, when written in binary form, is 1001. 1001 has two zeroes and two ones; thus, 9 is a round number. the integer 26 is 11010 in binary; since it has two zeroes and three ones, it is not a round number.
Obviusly, it takes cows a while to convert numbers to binary, so the winner takes a while to determine. bessie wants to cheat and thinks she can do that if she knows how many "round numbers" are in a given range.
Help her by writing a program that tells how should round numbers appear in the specified sive range given by the input (1 ≤ Start <Finish ≤2,000,000,000 ).
Input
Line 1: Two space-separated integers, respectively Start and Finish.
Output
Line 1: A single integer that is the count of round numbers in the random range Start .. Finish
Sample Input
2 12
Sample Output
6
This is a simulated mathematical problem for finding a regular law. Although WA has done three times, it is still AC after unremitting efforts. (* ^__ ^ *) Xi ......
Be careful and patient.
Code:
[Cpp]
<Span style = "font-family: FangSong_GB2312; font-size: 18px;" >#include <iostream>
Using namespace std;
Int num [35], sum [35], numa [35], numb [35];
Int dp [35] [35];
Int main ()
{
Int a, B, I, j, la, lb, len, suma, sumb, cnt, k;
Dp [0] [0] = 1;
For (I = 1; I <= 34; I ++) {dp [I] [0] = 1; dp [0] [I] = 0 ;}
For (I = 1; I <34; ++ I)
For (j = 1; j <= I; ++ j)
Dp [I] [j] = dp [I-1] [J-1] + dp [I-1] [j];
Memset (sum, 0, sizeof (sum ));
For (I = 2; I <= 34; I ++)
{
For (j = 0; j <= I/2-1; j ++)
Sum [I] + = dp [I-1] [j];
}
While (cin> a> B)
{
La = 0;
Int p =;
While (p)
{
Numa [la ++] = p % 2;
P = p/2;
}
Suma = 0;
K = 0;
For (I = 0; I <= la-1; I ++) suma + = sum [I];
For (I = la-2; I> = 0; I --)
{
If (numa [I] = 1)
{
For (j = (la + 1)/2-k-1; j <= I; j ++)
Suma + = dp [I] [j];
}
Else k ++;
}
P = B + 1; lb = 0;
While (p)
{
Numb [lb ++] = p % 2;
P = p/2;
}
Sumb = 0; k = 0;
For (I = 0; I <= lb-1; I ++) sumb + = sum [I];
For (I = lb-2; I> = 0; I --)
{
If (numb [I] = 1)
{
For (j = (lb + 1)/2-k-1; j <= I; j ++)
{
Sumb + = dp [I] [j];
}
}
Else k ++;
}
Cout <sumb-suma <endl;
}
Return 0;
}
</Span>