Back
Close

Digital root

Statement

 Goal

Your program must output the digital root of the number given in input.

The digital root is obtained by summing the individual digits of the number, then repeating the process on the result until the result has a single digit.

Special case: the digit root of 0 is 0.

For instance:
- the digital root of 12 is 3 (1 + 2)
- the digital root of 85 is 4 (8 + 5 = 13 -> 1 + 3 = 4)
Input
Line 1: N, the number to process, greater than 0
Output
Line 1: the digital root of N
Constraints
0<=N<2^32
Example
Input
12
Output
3

Game modes
Fastest, Shortest, Reverse

Test cases
Test 1 Test
Input
12
Output
3

Validator 1 Validator
Input
56
Output
2

Test 2 Test
Input
0
Output
0

Validator 2 Validator
Input
0
Output
0

Test 3 Test
Input
17
Output
8

Validator 3 Validator
Input
25
Output
7

Test 4 Test
Input
71
Output
8

Validator 4 Validator
Input
51
Output
6

Test 5 Test
Input
4294967292
Output
9

Validator 5 Validator
Input
1756476
Output
9

Test 6 Test
Input
95018375
Output
2

Validator 6 Validator
Input
98475
Output
6

Test 7 Test
Input
1850
Output
5

Validator 7 Validator
Input
582
Output
6

Test 8 Test
Input
7645
Output
4

Validator 8 Validator
Input
89506
Output
1

Solution language

Solution

Stub generator input