#B3978. Lucky Numbers

    ID: 11635 Type: Default 1000ms 256MiB

Lucky Numbers

Lucky Numbers

Dr. X defines a positive integer as a lucky number if in its binary representation every bit (either 0 or 1) has at least one adjacent bit equal to it. Formally, let the binary representation of a positive integer be \(s_0s_1\dots s_{n-1}\) (with \(n\ge 1\)). For every index \(i\) where an adjacent bit exists (either \(s_{i-1}\) or \(s_{i+1}\)), at least one of these adjacent bits must equal \(s_i\). Note that a number with a single binary digit is not considered lucky since it has no neighbor.

For example:

  • \((1)_2 = (1)_{10}\) is not lucky because the lone digit 1 is isolated.
  • \((110111)_2 = (55)_{10}\) is not lucky because the 0 in the middle is isolated (its neighbors are 1 and 1).
  • \((111110011)_2 = (499)_{10}\) is lucky.
  • \((110011001100)_2 = (3276)_{10}\) is lucky.

Given two positive integers \(a\) and \(b\), your task is to count how many lucky numbers are present in the interval \([a, b]\).

inputFormat

The input consists of two positive integers \(a\) and \(b\) (with \(a\le b\)), separated by a space.

outputFormat

Output a single integer representing the number of lucky numbers in the interval \([a, b]\) (inclusive).

sample

1 10
2