Possibly the test input uses uses windows line endings (containing a \r) - I don’t know whether C’s input will auto-convert for you. I think this might be the least likely explanation.
There’s a flaw in that, because you don’t consume the carriage return from the first line (the one with n and k on it), the first integer “read” is always 0, which eats up one of your n's and which is divisible by k (which is why you are subtracting one from count before you print it!)
Now, if the final number is not fully contained in the current buffer after reading the second-to-final number, then the loop will finish without ever reading the final number (because the spurious 0 read at the beginning eats up one of your n's), which will give the wrong answer if this final number is divisible by k.
Edit:
The results might vary from platform to platform, but I thinkthis exemplifies the problem - it has 2728 copies of the number 1000000000 (divisible by k = 4), but on my machine at least, your program gives the output 2727. It’s specifically tailored to break things if the buffer size is 30000.