I'm working on a SPOJ problem, INTEST. The goal is to specify the number of test cases (n) and a divisor (k), then feed your program n numbers. The program will accept each number on a newline of stdin and after receiving the nth number, will tell you how many were divisible by k.

The only challenge in this problem is getting your code to be FAST because k can be anything up to 10^7 and n can be as high as 10^9.

I'm trying to write it in Python and have trouble speeding it up. Any ideas?

Edit 2: I finally got it to pass at 10.54 seconds. I used nearly all of your answers to get there, and thus it was hard to choose one as 'correct', but I believe the one I chose sums it up the best. Thanks to you all. Final passing code is below.

Edit: I included some of the suggested updates in the included code.

Extensions and third-party modules are not allowed. The code is also run by the SPOJ judge machine, so I do not have the option of changing interpreters.