Determine the number of integers within the closed interval [X, Y] that can be represented as the sum of distinct powers of ; that is, the number of integers such that each power of is used at most once in the representation:
where a_i \in \{0, 1\}.
The first line contains the integers , , and (1 \le X \le Y \le 10^{100}, 2 \le b \le 10), separated by spaces.
Print a single integer — the number of integers in [X, Y] that can be expressed as the sum of distinct powers of .
Example 1
For X = 4, Y = 10, b = 3, the numbers are:
For X = 1, Y = 12, b = 2, the numbers are: