Re: Prime numbers



new programer wrote:
Thanks for trying to help me guys. Ok, so I understand that there is no
even prime number, besides 2. And also if, you mod any even number by
2, the result will obviously be 0. But then, how do I deal with
composite (non prime) numbers, that are odd.

I have come up with the following algorithm so far:
If inputNum Mod 2 = 0 Then (for even non prime numbers)
' not prime
elsif inputNum mod ?? = ?? Then (for odd non prime numbers)
' not prime
else (for prime numbers)
' number is prime

can you guys please help me out a little more.



               Thanks in advance.

I believe that any number that is not prime can be divided by either two or three. If you factor a number to the smallest factors you will (I think) always have either a 2 or 3 in the list of factors unless it is prime or the square of a prime. Someone who is more steeped in math will correct me if I'm wrong. So If my postulate is correct then...

isPrime = False
If inputNum Mod 2 and _
    inputNum Mod 3 and _
    sqr(inputNum) not an Integer then
    isPrime = True
End If

--
Steve Kelley
Protean Instrument Corp.
.