51. Digital Root

Acceptance — 0 accepted 0 submissions

Easy
LoopsMath
No companies listed
In numerology, people keep adding the digits of a number until a single digit is left. This is called the digital root.

Example: 9875 → 9+8+7+5 = 29 → 2+9 = 11 → 1+1 = 2.
Given n, find its digital root.

Input Format
A single integer n.

Output Format
Print the digital root.

Constraints
• 0 ≤ n ≤ 10^18

Example 1

Input
9875
Output
2

Explanation 9875 → 29 → 11 → 2.

Example 2

Input
38
Output
2

Explanation 3 + 8 = 11 → 1 + 1 = 2.

Example 3

Input
7
Output
7

Explanation Already a single digit.

Acceptance —
Accepted 0
Submissions 0
Auto-save
Saved Ln 1, Col 1
Submit a solution to see its status here.
Input
Expected Output
2
No results yet
Run your code to test it against the sample cases.
Problem List