#P1532. 卡布列克圆舞曲

卡布列克圆舞曲

Description

Kaprekar was a mathematician. He discovered that for any four-digit number not composed of completely identical digits: if you reorder its digits to form the largest number and the smallest number, then subtract the smaller from the larger; if the difference has fewer than four digits, pad with leading zeros; and repeat this process, it will eventually become a fixed number 61746174, which is the Kaprekar constant. For example:

43211234=30874321-1234=3087.

8730378=83528730-378=8352.

85322358=61748532-2358=6174.

76411467=61747641-1467=6174.

If a K-digit number is processed in the same way, it does not become a single number but forms a cycle among several numbers, called the Kaprekar Waltz. For example, for the five-digit number 5432154321:

5432112345=4197654321-12345=41976.

9764114679=8296297641-14679=82962.

9862222689=7593398622-22689=75933.

9753333579=6395497533-33579=63954.

9654334569=6197496543-34569=61974.

9764114679=8296297641-14679=82962.

We call 82962, 75933, 63954, 61974 the repeating cycle, i.e., the Kaprekar Waltz.

Input Format

Multiple lines. Each line contains a starting integer nn for which to find the "Kaprekar Waltz" (n<231n<2^{31}).

Output Format

For each input integer, output the corresponding cycle terms on one line, separated by spaces.

4321
54321

6174
82962 75933 63954 61974

Hint

Translated by ChatGPT 5