With your use of if..else-if there, you better read the following: But...Anything Can Happen! - The Daily WTF

And certainly have a read of this too: Sieve of Eratosthenes - Wikipedia, the free...