#t120. 二进制回文数
二进制回文数
Binary Palindromes
Problem Description
For a positive integer , convert it to its binary representation without leading zeros. If this binary sequence reads the same from left to right as from right to left, the number is called a binary palindrome. For example, in binary is , a binary palindrome; in binary is , not a binary palindrome.
Your task: given a positive integer , count how many binary palindromes lie in the range from to .
Input Format
One line containing a positive integer .
Output Format
One line containing one number: the count of binary palindromes in the range to .
Sample Input
15
Sample Output
6
Sample Explanation
For input , we list all binary palindromes from to :
- in binary is , a palindrome;
- in binary is , not a palindrome;
- in binary is , a palindrome;
- in binary is , not a palindrome;
- in binary is , a palindrome;
- in binary is , not a palindrome;
- in binary is , a palindrome;
- in binary is , not a palindrome;
- in binary is , a palindrome;
- in binary is , not a palindrome;
- in binary is , not a palindrome;
- in binary is , not a palindrome;
- in binary is , not a palindrome;
- in binary is , not a palindrome;
- in binary is , a palindrome.
Thus there are binary palindromes, so output .
Constraints