# Counting Integers

Determine the number of valid 6-digit integers (ie. no leading zeros) where no digits can be repeated and such that it is divisible by 4

Fact: integer is divisible by 4 if the last two digits are divisible by 4 (eg. 416, 756)

There are

• $8\times7\times6\times5\times6$ valid 6-digit integers that end in $04, 08, 20, 40, 60, 80$
(ie. divisible by 4, contains one zero and no digit repeated)

• $7\times7\times6\times5\times16$ valid 6-digit integers that end in
$12, 16, 24, 28, 32, 36, 48, 52, 56, 64, 68, 72, 76, 84, 92, 96$
(ie. divisible by 4, does not contain any zeros and no digit repeated)

$\therefore$ There are $(8\times7\times6\times5\times6) + (7\times7\times6\times5\times16)$ valid 6-digit integers where no digits can be repeated and such that it is divisible by 4

My question:

Is there a better (as in less error-prone) way to solve the original problem by hand?
(enumerating the two-digit numbers that are divisible by 4 and adding the amount of such integers correctly was a bit problematic for me)

• I think this is the best way as you should separate cases. – Abr001am Jan 20 '18 at 20:26

Is there a better (as in less error-prone) way to solve the original problem?

This might not be the answer you'd want to hear, but yes. It's simply counting. And computers are really, really good at this. As a mathematician in the modern world I think it's important to learn at least the basics of programming, as numerical exploration can often help you form quick hypotheses and intuitions, and use those to speed up finding references, proofs, or coming up with your own.

So in this example, we generate every valid 6-digit integer such that it is divisible by 4 and has no repeated digits. Then we simply display how many such integers we generated. For example in Python:

no_repeated_digits = lambda n: len(str(n)) == len(set(str(n)))
numbers = [n for n in range(100000, 999999) if n % 4 == 0 and no_repeated_digits(n)]
print(len(numbers))


Which instantly gives our result 33600.

• I probably should have clarified, but I am asking how I would solve this by hand – wybkqqnob Jan 20 '18 at 19:15