Exceeding time limit in Python

This is my solution for the enormous input test problem, and it is exceeding time limit.

n, k = [int(_) for _ in raw_input().split(" ")]
a = 0
for i in xrange(n):
    if int(raw_input())%k==0:
print a

What is wrong with this code?

@admin, something wrong with my code or the server?

n, k = [int(_) for _ in raw_input().split(" ")]

The problem lies here.

Taking an input as string and splitting is has to be much slower than fast inputs like scanf, where you read byte by byte.

1 Like

It’s just happening one time, and pls. suggest a workaround

Nothing wrong with the server. Python is very slow in such cases and your input method is slow.
It is good enough for most of the normal problems without huge input but this problem has large input. There is noting you do other than look at alternative faster methods

Just look at some of the other AC submissions which use sys.stdin and
and a2i(ascii to integer) function. Here are a few links to such submissions : link 1 time : 20.66(among the fastest).Other methods : link 2 . link 3