Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Edutopia

  • 2 years ago

Advice on optimizing this program for summing primes:

  • This Question is Open
  1. Edutopia
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    import math def SumPrimesBelow(num): s=0 composites=set([]) for i in range(2,num+1): sieve=[p*i for p in range(2,int(num/i+1))] composites.update(sieve) num = set(range(2,num+1)) primes_below_num = num.difference(composites) for prime in primes_below_num: s+=prime return s print SumPrimesBelow(2000000)

  2. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy