#K92547. Repeated Sum of Digits Transformation
Repeated Sum of Digits Transformation
Repeated Sum of Digits Transformation
You are given a collection of integer sequences. For each integer in these sequences, you are required to repeatedly replace it with the sum of its digits until the result has only one digit. Note that for negative integers, consider the absolute value, and the final result must be non‐negative.
For example, the number 12
becomes 1+2 = 3
, and the number -23
becomes |-23| = 23, 2+3 = 5
. You need to apply this transformation on each integer and output the resulting sequences.
The input begins with an integer T representing the number of sequences, followed by T lines, each containing a space‐separated list of integers. For each sequence, output a line containing the transformed integers separated by a single space.
The process of summing digits can be written in LaTeX as follows:
$$ \text{while } n \ge 10:\quad n = \sum_{d \in \text{digits}(n)} d $$
inputFormat
The first line of input contains a single integer T (1 ≤ T ≤ 100
), the number of sequences.
Each of the next T lines contains a sequence of space-separated integers. Each integer n satisfies |n| ≤ 10^9
.
outputFormat
Output T lines, each corresponding to an input sequence. For each sequence, print the transformed integers (where each integer is replaced by the repeated sum of its digits) separated by a single space.
## sample4
12 45 -23
908 320 155
-9 81 111
56 77 19
3 9 5
8 5 2
9 9 3
2 5 1
</p>