Quantcast
Channel: Sieve of Eratosthenes in Python - Stack Overflow
Browsing all 4 articles
Browse latest View live

Answer by Mark Ransom for Sieve of Eratosthenes in Python

Your use of the square root is terminating your results early. If you want to yield all the primes up to 100, your loop has to go to 100.The square root isn't necessary in your code because it's...

View Article



Answer by Floris for Sieve of Eratosthenes in Python

"I am told I need to use square root". Why do you think that is? Usually the sieve of E. is used to remove all "non prime" numbers from a list; you can do this by finding a prime number, then checking...

View Article

Answer by Nik for Sieve of Eratosthenes in Python

Your logic is correct, except for the for loop. It terminates after reaching sqrt(n)-1. For p(100), it will run only from 2 to 9. Hence you get prime numbers only till 9.

View Article

Sieve of Eratosthenes in Python

I am trying to write a python function to return the number of primes less than a given value and the values of all the primes. I need to use the Sieve of Eratosthenes algorithm. I believe I'm missing...

View Article
Browsing all 4 articles
Browse latest View live




Latest Images