Python中的NZEC错误 [英] NZEC error in Python

查看:31
本文介绍了Python中的NZEC错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一段简单的代码,假设读取 n 个数字并假设打印这 n 个数字中有多少个数字可以被 k 整除

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 

我在 codechef 上遇到了 NZEC 错误.有人可以指出问题出在哪里吗?自上周以来,这个 NZEC 错误一直困扰着我.我是 python 的新手,在互联网上搜索了很多,但找不到任何具体的东西.我得到的答案是,当堆栈大小超出限制时会发生 NZEC 错误.但是我的这段代码有什么问题?

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?

推荐答案

我想 codechef 的问题是这个.您应该考虑到 n 和 k 的值大约为 10^7,这可能是您的程序有问题.

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.

此外,n 和 k 在同一行上.您使用了 raw_input 两次,因此您正在阅读两行.这可以通过使用来解决:

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:

n, k = raw_input().split(" ")
n = int(n)
k = int(k)

如果这没有帮助,您可以尝试遍历 xrange,或者使用不同的算法.

If that won't help, you could try looping over an xrange instead, or using a different algorithm.

这篇关于Python中的NZEC错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆