我要运行以下命令:
import sys
f = open("results.txt", "w+")
for n in range(1, 100000):
counter = 0
for i in range(1, n-1):
if(i**2 % n ==2):
counter = counter+1
print('There are', counter, 'solutions in Z_',n,'Short', counter,'in', n, file=f )
f.close()
但是程序中断得太早,例如30227。 我不知道为什么。
编辑:然后我在第一个“ for”后面添加了print(n),如下所示:
import sys
f = open("results.txt", "w+")
for n in range(1, 100000):
print(n)
counter = 0
for i in range(1, n-1):
if(i**2 % n ==2):
counter = counter+1
print('There are', counter, 'solutions in Z_',n,'Short', counter,'in', n, file=f )
f.close()
并且收到了我想要的所有100000行的文件。
然后我尝试评估初始代码,并再次收到最后一行的文件
There are 2 solutions in Z_ 5783 Short 2 in 5783
There are 0 solutions in Z_
有人可以帮我吗?