Concatenation of Consecutive Binary Numbers
Given an integer n, return the decimal value of the binary string formed by concatenating the binary representations of 1 to n in order, modulo 10^9 + 7.
Example 1
Input
n = 1Output
1"1" in binary corresponds to the decimal value 1.
Example 2
Input
n = 3Output
27In binary, 1, 2, and 3 correspond to "1", "10", and "11"; concatenating them gives "11011", which corresponds to the decimal value 27.
Constraints
- 1 <= n <= 10^5