def prime(x):
for i in range(2,x):
if x%i==0:
return False
elif i==x-1:
return True
output=filter(prime,range(2,1001))#区分于map函数
output
b = list(output)
c = 0
for i in b:
c = c + i;
print(c)#我的是jupyter编译器,如需要展示素数直接print(b)
你好的!
直接运行代码:
i = [x for x in range(2,1000) if not [y for y in range(2,x) if x%y == 0]]
s = 0
for a in i:
s +=a;
print (s)
请您采纳
from math import sqrt
def is_prime(n):
if n == 1:
return False
for i in range(2, int(sqrt(n))+1):
if n % i == 0:
return False
return True
count = 0
for i in range(1, 1000):
if is_prime(i):
count = count + 1
print('{}:{}'.format(count, i))
m=0
s=0
for i=100 to 1000
for j=1 to i
if mod(i,j)=0
n=n+1
if n>=2
m=m+1
s=s+i
??i
if mod(m,5)=0
?
endif
endif
endif
next
next
?s
return
答案补充
m=0
s=0
for i=100 to 1000
for j=1 to i
if mod(i,j)=0
n=n+1
endif
if n>=2
m=m+1
s=s+i
??i
if mod(m,5)=0
?
endif
endif
next
next
?s
return
这就对了
答案补充
m=0
i=0
p=0
s=0
n=100
do while n<1000
do while m<=n
m=m+1
if mod(n,m)=0
i=i+1
endif
enddo
if i>=2
??n
s=s+n
p=p+1
endif
if mod(p,5)=0
?
endif
n=n+1
enddo
? s
return
很简单的。。