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 .
Even more remarkable is that if we start from any digit number and repeat this process of sorting and subtracting, we'll eventually end up with or immediately with if all digits are equal.
This also works with numbers that have less than digits if we pad the number with leading zeroes until we have digits.
E.g. let's start with the number :
is called the Kaprekar constant. The process of sorting and subtracting and repeating this until either 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 digits and a base , a Kaprekar constant exists.
E.g. base :
base :
Define to be the Kaprekar constant in base for digits.
Define the function to be
if or if written in base consists of identical digits
the number of iterations it takes the Kaprekar routine in base to arrive at , otherwise
Note that we can define for all integers . If written in base takes less than digits, the number is padded with leading zero digits until we have digits before applying the Kaprekar routine.
Define as the sum of for .
E.g.
Find the sum of for .
Give the last digits as your answer.
Write-up coming later
The complete problem is available here. An approach, code, and answer will be added later.