Output all prime numbers up to a specified integer n.
This is a phone screen question from one of my interviews. An efficient way to generate prime numbers is using Sieve of Eratosthenes. We store the primes in a table of true false values, so we are able to determine if a number is a prime number efficiently using this table.
Below is one possible implementation, you can read more in-depth analysis about generating prime numbers in Programming Pearls.
Read full article from Finding prime numbers | LeetCode
No comments:
Post a Comment