Search code examples
javamathbit-manipulationmathematical-optimizationdivision

Determining divisibility of number by 11 for large numbers


I'm looking for a way to determine a large number is divisible by 11

My understanding: (sum of digits at even positions - sum of digits at odd positions) % 11 == 0 ==> yes

This works for some examples.

Example: 3816 => (3+1) - (8+6) = -10
In case of negative, do we need to consider 2's complement of -10 for modulo % with 11?

Similarly: 391679 => 11 - 24 = -13 (this number is also divisible by 11)

Could you please help me understand this? thanks in advance.


Solution

  • The numbers 3816 and 391679 are not divisible by 11. Just validating the difference between the sum of alternate digits with %(modulo) 11 is enough to check divisibility by 11, even if the difference is negative.