Problems > Digital Root > Editorial

Digital Root — Solution & Editorial

Back to the Problem

Simulate the digit-sum loop (at most a few iterations), or use the identity: the digital root of N > 0 is 1 + (N−1) mod 9.

Complexity: O(log N)