Monday, November 27, 2006

quick mod by 11

1==1 (mod 11)
10==-1 (mod 11)
100==1 (mod 11)
1000==-1 (mod 11)

Therefore 123456 == 6 - 5 + 4 - 3 + 2 - 1 (mod 11) == 3 (mod 11)
Obviously you may need to do a further % operation after adding and subtracting digits, but it should be reasonably fast.

3 comments:

  1. what is 90 % 11 ?

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. 90 % 11 = 0 - 9 = -9 % 11 = 2

    ReplyDelete