http://qs321.pair.com?node_id=203844


in reply to YAPNC: Yet another prime number checker?

First of all: the used algorithm passed '1' for a prime while it isn't! A prime should have two and only two different integer divisors...

Secondly, you could speed things up a little more: you only need to check all integer numbers up to ceil( $input / 2 ) because of the commutative properties of integers (2*3 == 3*2).
Furthermore, prime are always (except for '2', so almost always) odd numbers, so you could skip them in your test for even more speed improvement!

-- JaWi

"A chicken is an egg's way of producing more eggs."