数学规则表明我的“程序”给出了错误的答案。
如果您能检查一下这段代码并告诉我其中的问题,我将不胜感激。我知道问题出在 ll = []
行之后的某处。我只是无法确定它的确切原因。但我确实知道 所有小于 n 的素数的对数之和小于 n。我的程序违反了这条规则。
代码如下:
from math import log
lp = [] ## create a list
for n in range(2,10000):
for x in range(2,n):
if n % x == 0:
break
else:
lp.append(n) ## fill that list with the primes
##print lp[500] found the value of lp[500]
ll = [] ## create a second list
for i in range(2, lp[500]):
if i < 3581: ## this is the number corresponding to lp[500]
i = log(i, )
ll.append(i) ## fill the second list with logs of primes
print sum (ll), 3581, sum(ll)/3581`
最佳答案
您的第二个列表不仅包含质数的对数,还包含 2 到 lp[500]
之间的所有整数的对数。
关于python - 计算素数对数的程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8118606/