#C5588. Festive Spirit
Festive Spirit
Festive Spirit
Given a positive integer n, the task is to compute its Festive Spirit. The Festive Spirit is defined as the process of repeatedly summing the digits of n until only a single digit remains.
Formally, if we define the sum of the digits of n as $$S(n)=\sum_{d\in\text{digits}(n)} d,$$ then the Festive Spirit of n is obtained by applying S repeatedly until the result is a single digit. In other words, we seek the value of $$festive\_spirit(n) = S(S(\ldots S(n)\ldots))$$ where the operation is repeated until a single digit is reached.
For example, if n = 9875, then:
- Step 1: 9 + 8 + 7 + 5 = 29
- Step 2: 2 + 9 = 11
- Step 3: 1 + 1 = 2
Thus, the Festive Spirit of 9875 is 2.
inputFormat
The input consists of a single line containing a positive integer n (0 < n < 1018).
outputFormat
Output a single digit which is the Festive Spirit of n.
## sample9875
2
</p>