# Thread: Prime Prime Prime Help Help Help

1. Which rule restricted answering to this thread? 5?
We should see the goal of the rule. It wants to prevent dead topics to come on first page. Answering to an unanswered thread is different. For example maybe I have had asked a very hard question that nobody could answered, but 5 months later somebody came and answered it. You think it is illegal? Of course it is not. It is the goal of the forum.

2. Originally Posted by mltngpot
all prime numbers (except 2) are prime, once again wasting precious processes.
shouldn't that read, all prime numbers, other than 2, are odd. ?

so testing for if it is odd, then seeing if it has ANY divisors other than 1 and itself is all you need to do. [ test for division by 2, 3, 5 ]
iand non prime number with divide by one or more of these three.
not all odd number have a square root that is an integer. ie: 15 is not prime, yet does not square root either to an integer. so testing for a square root is not going to result in a prime number.

3. sorry, not thinking, all prime numbers are odd except two.
and no prime number will have an integer sqrt, however, getting the sqrt of the number before hand will eliminate checking the sqrt multiple times. any program like this, is going to be run (most likely) using large numbers, since the small ones are readily available and the math is easy. 2, 3, 5, 7, 11.... so the amount of processes run cuts down signifigantly.

if you had say
Code:
```  sqrtnum = sqrt(iNum);
for (count = 0; count < sqrtnum; count++)```
you would cut down on the execution of the sqrt. you could even make it faster, by checking to see if sqrtnum was an integer before the loop, so in the case of iNum being 100, the sqrt would be 10, thus skipping the loop. and making the function exponentially faster. in this case, it would skip running the loop 10 times, (or 4 times faster if you only check against prime numbers), and if you wanted to get really smart, you would do a check against 2 and 5 also before the loop, and only check numbers ending in 1, 3, 7,9 because if its even its composite as well as if it ends in 5.

Popular pages Recent additions