Thank you very much chroot. You've allowed me to complete my program.
I got the idea when I was trying to solve the following maths problem that was once set in an Oxbridge interview for prospective maths students:
Of the numbers 1, 2, 3, ..., 6000, how many are not multiples of 2, 3 or 5...