我正在尝试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)
答案 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)