Problem
Add up the digits of n. If the result has more than one digit, add up its digits again. Repeat until a single digit remains.
Implement digital_root(n).
Input
n: A positive integer.
Output
Return the final single digit.
Constraints
1 ≤ n ≤ 10¹⁸
Examples
Example 1
Input:
n = 999
Expected output:
expected = 9
Input:
long long n = 999;
Expected output:
long long expected = 9;
Input:
long n = 999;
Expected output:
long expected = 9;
Explanation
9 + 9 + 9 = 27, then 2 + 7 = 9.
Example 2
Input:
n = 38
Expected output:
expected = 2
Input:
long long n = 38;
Expected output:
long long expected = 2;
Input:
long n = 38;
Expected output:
long expected = 2;
Explanation
3 + 8 = 11, then 1 + 1 = 2.