this is a simple piece of code which is suppose to read n numbers and suppose to print how many numbers out of these n numbers are divisible by k
n=int(raw_input())
k=int(raw_input())
ans=0
while n > 0:
t=int(raw_input())
if(t%k == 0):
ans = ans + 1
n = n - 1
print ans
I got a NZEC error for this on codechef. Can someone point out where does the issue lie? This NZEC error has bothered me a lot since last week. I am new to python and have searched a lot on internet but could not find anything concrete. I got the answer that NZEC error occurs when the stack size goes beyond limit. But what is the issue with my this code?
I suppose the codechef question is this one. You should take in account that the value of n and k are around 10^7, which could be a problem with your program.
Also, n and k are on the same line. You are using raw_input twice, so you are reading two lines. This can be solved by using:
If that won’t help, you could try looping over an xrange instead, or using a different algorithm.