How would you go about coding a function to find the first x number of primes? I just can't figure out how to even start it. I'd greatly appriciate any help. Thanks

Printable View

- 09-17-2001UnregisteredPrime Numbers
How would you go about coding a function to find the first x number of primes? I just can't figure out how to even start it. I'd greatly appriciate any help. Thanks

- 09-17-2001zen
A simple way of working them out is to divide each number by every number lower than itself (except 1) and if none of the divisions result in a remainder of zero then you have a prime number (there are ways of speeding up this algorithm).

- 09-17-2001Zach L.
Not the most efficient means of checking for primes, but it works. ;)

Actually, you do not need to check divisibility for all numbers less than the one you are currently testing, only all numbers less than or equal to the square root of the number. - 09-18-2001UnregisteredThanks
Cool. Thanks a lot. :)