46. Digital Root
Core1000 ms256 MBSolved by 0%
The digital root is what you get by adding a number's digits, then adding the digits of that result, and repeating until a single digit remains.
For 9875: 9+8+7+5 = 29, then 2+9 = 11, then 1+1 = 2. So the digital root is 2.
Read a non-negative integer and print its digital root.
Constraints - `0 ≤ n ≤ 1000000000000000000`
Input
A single line containing one integer n.
Output
Print one integer between 0 and 9, the digital root.
Input9875
Output2
Noteis the worked example from the statement
Input0
Output0
Noteis zero, whose digital root is zero, the shortcut formula fails here unless handled
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.