eolymp
bolt
Try our new interface for solving problems
Problems

Counting Ones

Counting Ones

Carl is right now the happiest child in the world: he has just learned this morning what the binary system is. He learned, for instance, that the binary representation of a positive integer $k$ is a string $a_na_{n-1} ... a_1a_0$ where each $a_i$ is a binary digit $0$ or $1$, starting with $a_n = 1$, and such that \includegraphics{https://static.e-olymp.com/content/7f/7fb1dbe815ab106463567468a6b41ada392bd6bc.jpg} It is really nice to see him turning decimal numbers into binary numbers, and then adding and even multiplying them. Caesar is Carl's older brother, and he just can't stand to see his little brother so happy. So he has prepared a challenge: "Look Carl, I have an easy question for you: I will give you two integers $a$ and $b$, and you have to tell me how many $1$'s there are in the binary representation of all the integers from $a$ to $b$ inclusive. Get ready". Carl agreed to the challenge. After a few minutes, he came back with a list of the binary representation of all the integers from $1$ to $100$. "Caesar, I'm ready". Caesar smiled and said: "Well, let me see, I choose $a = 10^{15}$ and $b = 10^{16}$. Your list will not be useful". Carl hates loosing to his brother so he needs a better solution fast. Can you help him? \InputFile A single line that contains two integers $a$ and $b~(1 \le a \le b \le 10^{16})$. \OutputFile Output a line with an integer representing the total number of digits $1$ in the binary representation of all the integers from $a$ to $b$ inclusive.
Time limit 1 second
Memory limit 128 MiB
Input example #1
2 12
Output example #1
21
Author Ray Williams Robinson Valiente
Source 2013 ACM Regional Latino America, Problem C