Facebook
From Harmless Madrill, 2 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 30
  1. from math import sqrt,ceil
  2. n=10
  3. list=[True]*n
  4. list[0]=False
  5. list[1]=False
  6. root=ceil(sqrt(n))
  7. for i in range(2,root):
  8.     if list[i]==False:
  9.         continue
  10.     for j in range(i+1,len(list)):
  11.         if j%i==0:
  12.             list[j]=False
  13. sum=0
  14. for i in range(n):
  15.     if list[i]:
  16.         sum+=i
  17.  
  18. print(list,sum)
  19.