Once upon a time Baron Munchhausen traveled to the Moon. After that he often tells interesting stories about the Selenites. Recently Baron told us about their numeric system. They use a notation with negative radix!Negative radix is quite hard for Humans, and even for Munchhausen. So, Baron did a trick to help himself on the Moon. He remembered all the numbers between 0 and n inclusively, which have the same notation for both Selenites’ negative radix k and a more convenient positive radix k. Munchhausen claims that he did that easily. But, you know, Baron can exaggerate a little. To catch him, you have to count how many numbers he must have remembered. Note: the k-radix notation of a number x is a sequence of integers a0, a1, …, ap such that 0 ≤ ai < |k| and ∑i=0paiki=xsum_{i=0}^{p}a_icdot k^i=x∑i=0paiki=x∑p i=0 ai· ki = x.
Once upon a time Baron Munchhausen traveled to the Moon. After that he often tells interesting stories about the Selenites. Recently Baron told us about their numeric system. They use a notation with negative radix! Negative radix is quite hard for Humans, and even for Munchhausen. So, Baron did a trick to help himself on the Moon. He remembered all the numbers between 0 and n inclusively, which have the same notation for both Selenites’ negative radix −k and a more convenient positive radix k. Munchhausen claims that he did that easily. But, you know, Baron can exaggerate a little. To catch him, you have to count how many numbers he must have remembered. Note: the k-radix notation of a number x is a sequence of integers a0, a1, …, ap such that 0 ≤ ai < |k| and ∑i=0pai⋅ki=xsum_{i=0}^{p}a_icdot k^i=x∑i=0pai⋅ki=x∑p i=0 ai· ki = x.
