Comment by afiodorov
1 year ago
a = [int(x) for x in str(n)][::-1]
assert n == sum(d*(10**i) for i, d in enumerate(a))
Now when you're operating mod 9, 10 == 1 % 9, thus
10**i == 1 % 9
Comes from the fact that
(a*b) % 9 == (a % 9) * (b % 9)
Now using
(a+b) % 9 == (a % 9) + (b % 9)
We get that that sum(a) and n are same mod 9.
Thank you for that.