Slacker News Slacker News logo featuring a lazy sloth with a folded newspaper hat
  • top
  • new
  • show
  • ask
  • jobs
Library
← Back to context

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.

1 comment

afiodorov

Reply

ryao  1 year ago

Thank you for that.

Slacker News

Product

  • API Reference
  • Hacker News RSS
  • Source on GitHub

Community

  • Support Ukraine
  • Equal Justice Initiative
  • GiveWell Charities