#t120. 二进制回文数

二进制回文数

Binary Palindromes

Problem Description

For a positive integer nn, 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, 99 in binary is (1001)2(1001)_2, a binary palindrome; 1212 in binary is (1100)2(1100)_2, not a binary palindrome.

Your task: given a positive integer nn, count how many binary palindromes lie in the range from 11 to nn.

Input Format

One line containing a positive integer nn.

Output Format

One line containing one number: the count of binary palindromes in the range 11 to nn.

Sample Input

15

Sample Output

6

Sample Explanation

For input 1515, we list all binary palindromes from 11 to 1515:

  • 11 in binary is 11, a palindrome;
  • 22 in binary is 1010, not a palindrome;
  • 33 in binary is 1111, a palindrome;
  • 44 in binary is 100100, not a palindrome;
  • 55 in binary is 101101, a palindrome;
  • 66 in binary is 110110, not a palindrome;
  • 77 in binary is 111111, a palindrome;
  • 88 in binary is 10001000, not a palindrome;
  • 99 in binary is 10011001, a palindrome;
  • 1010 in binary is 10101010, not a palindrome;
  • 1111 in binary is 10111011, not a palindrome;
  • 1212 in binary is 11001100, not a palindrome;
  • 1313 in binary is 11011101, not a palindrome;
  • 1414 in binary is 11101110, not a palindrome;
  • 1515 in binary is 11111111, a palindrome.

Thus there are 66 binary palindromes, so output 66.

Constraints

1≤n≤1051 \le n \le 10^5