#C6125. Repeated Digit Sum
Repeated Digit Sum
Repeated Digit Sum
You are given a non-negative integer (n). Define a function (f(n)) as follows:
[ f(n) = \begin{cases} n, & \text{if } 0 \le n < 10, \ f\Big(\sum_{d \in D(n)} d\Big), & \text{if } n \ge 10, \end{cases} ]
where (D(n)) represents the set of digits of (n). In other words, repeatedly sum the digits of (n) until the result is a single digit. Your task is to compute (f(n)) for the given input.
inputFormat
The input consists of a single non-negative integer (n) (read from standard input).
outputFormat
Output a single integer representing the single digit obtained after repeatedly summing the digits of (n) (printed to standard output).## sample
38
2