Otherwise, let p now equal this number (which is the next prime), and repeat from step 3Īt the end when the algorithm terminates, all the numbers in the list that are not marked are the prime numbers. Find the first number greater than p in the list that is not marked.note that some of them may have already been marked Starting from p, count up in increments of p and mark each of these numbers greater than p itself in the list.Initially, let p be equal 2, the first prime number.Create a list of consecutive integers from 2 to n: (2, 3, 4, …, n).Let's take a look at the steps of this algorithm: There's yet another efficient method which could help us to generate prime numbers efficiently, and it's called Sieve Of Eratosthenes.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |