CodeEval双方挑战

时间:2016-10-06 05:39:26

标签: python-3.x

我正在尝试this challenge,我想我已经解决了。但是当我提出解决方案时,它总是徘徊在60%到70%之间。我的解决方案出了什么问题?

from sys import argv
with open(argv[1],'r') as test_cases:
    for item in test_cases:
        item = int(item)
        count = 0
        for i in range(int((item/2)**0.5)+1):
            if ((item - i**2)**0.5) % 1 == 0:
                count+=1
        print(count)

1 个答案:

答案 0 :(得分:0)

您错过了阅读第一个值 N (test_cases的数量)

with open(argv[1],'r') as test_cases:
    N = int(next(test_cases)) #get rid of it :)
    for item in test_cases:
        item = int(item)
        count = 0
        for i in range(int((item/2)**0.5)+1):
            if ((item - i**2)**0.5) % 1 == 0:
                count+=1
        print(count)