As an icebreaker, the mentor asks everyone to reduce their student ID number to a single "lucky digit" by repeatedly summing its digits — Fahim needs a program to automate this for the whole batch. Read a positive integer N and repeatedly replace N with the sum of its digits until N becomes a single digit (0-9). Print the final single digit. (This is the "digital root" — try to also think of the O(1) math shortcut using mod 9, not just simulation.)
Input
One integer N.
Output
A single digit, the digital root of N.
Constraints
1 ≤ N ≤ 10^18
Sample Input
9875
Sample Output
2
main.c
Loading editor…
Write C, then Run (custom I/O) or Submit (sample tests). ⌘/Ctrl+Enter submits.