#K14671. Sum Digits Until Single Digit
Sum Digits Until Single Digit
Sum Digits Until Single Digit
You are given a list of non-negative integers. For each integer, you need to repeatedly compute the sum of its digits until the resulting sum is a single digit. For example, given the integer 29, you compute 2 + 9 = 11, and since 11 is not a single digit, you continue by computing 1 + 1 = 2. The final result for 29 is 2.
The task is to process an input list of integers and output a corresponding list where each number has been reduced to its single-digit sum.
Note: If an integer is already a single digit, it remains unchanged.
The mathematical process can be described by the following iterative relation: \[ f(n) = \begin{cases} n, & \text{if } n < 10 \\ f\Bigl(\sum_{d\in\text{digits}(n)} d\Bigr), & \text{if } n \geq 10 \end{cases} \]
inputFormat
The input is given via standard input (stdin) and consists of two lines:
- The first line contains a single integer n representing the number of integers.
- The second line contains n non-negative integers separated by spaces.
outputFormat
The output should be printed via standard output (stdout). It consists of a single line containing n integers separated by a single space. Each integer is the result of reducing the corresponding input integer to a single digit by repeatedly summing its digits.
## sample4
1 2 3 9
1 2 3 9
</p>