Problem 414
Kaprekar constant
6174 is a remarkable number; if we sort its digits in increasing order and subtract that number from the number you get when you sort the digits in decreasing order, we get 7641-1467=6174.
Even more remarkable is that if we start from any 4 digit number and repeat this process of sorting and subtracting, we’ll eventually end up with 6174 or immediately with 0 if all digits are equal.
This also works with numbers that have less than 4 digits if we pad the number with leading zeroes until we have 4 digits.
E.g. let’s start with the number 0837:
8730-0378=8352
8532-2358=6174
6174 is called the Kaprekar constant. The process of sorting and subtracting and repeating this until either 0 or the Kaprekar constant is reached is called the Kaprekar routine.
We can consider the Kaprekar routine for other bases and number of digits.
Unfortunately, it is not guaranteed a Kaprekar constant exists in all cases; either the routine can end up in a cycle for some input numbers or the constant the routine arrives at can be different for different input numbers.
However, it can be shown that for 5 digits and a base b = 6t+3≠9, a Kaprekar constant exists.
E.g. base 15: (10,4,14,9,5)15
base 21: (14,6,20,13,7)21
Define Cb to be the Kaprekar constant in base b for 5 digits. Define the function sb(i) to be
- 0 if i = Cb or if i written in base b consists of 5 identical digits
- the number of iterations it takes the Kaprekar routine in base b to arrive at Cb, otherwise
Note that we can define sb(i) for all integers i < b5. If i written in base b takes less than 5 digits, the number is padded with leading zero digits until we have 5 digits before applying the Kaprekar routine.
Define S(b) as the sum of sb(i) for 0 < i < b5.
E.g. S(15) = 5274369
S(111) = 400668930299
Find the sum of S(6k+3) for 2 ≤ k ≤ 300.
Give the last 18 digits as your answer.
卡布列克常数
6174是个神奇的数;如果我们用将它的数字按降序排列组成的数减去将它的数字按升序排列组成的数,我们得到7641-1467=6174。
更神奇的是,如果我们从任意四位数出发,重复这个排列和相减的过程,最终我们都会得到6174,或者当每一位数字都相同时得0。
即使这个数没有4位,我们可以将其补上前导零凑足四位,上述结论同样成立。
例如,我们从数0837开始:
8730-0378=8352
8532-2358=6174
6174被称为卡布列克常数。这个排序和相减直至到达0或卡布列克常数的过程称为卡布列克路径。
对于其他进制和位数,我们也可以考察相应的卡布列克路径。
不幸的是,并不能保证在所有情况下都存在卡布列克常数;有时这个路径会最终进入一个循环,或者从不同的数出发最后会到达不同的常数。
然而,可以证明,对于5位数,以及b = 6t+3≠9 进制,存在卡布列克常数。
例如,在15进制下为: (10,4,14,9,5)15
在21进制下为: (14,6,20,13,7)21
记Cb是b进制5位数的卡布列克常数。定义函数sb(i)为
- 0,如果i = Cb,或者i在b进制下5个数字全部相同。
- 否则为在b进制下从这个数出发经过卡布列克路径到达Cb的迭代次数。
注意sb(i)定义在所有整数i < b5上。即使i在b进制下不足5位,我们都可以在开始卡布列克路径之前给它加上前导零补足5位。
定义S(b)是所有0 < i < b5的函数sb(i)的和。
例如,S(15) = 5274369
S(111) = 400668930299
对于2 ≤ k ≤ 300,求S(6k+3)的和。
给出这个数的最后18位作为你的答案。