Not sure if I should\'ve posted this on math.stackexchange instead, but it includes more programming so I posted it here.
The question seems really simple, but I\'ve
range(k,max) does not include max, so you're really checking up to and including 998 (while 999 is a multiple of 3). Use range(1,1000) instead.
range(k,max)
max
range(1,1000)