Isn't calling is_int and checking if the number contains a decimal redundant?
A function like that would be acceptable for small numbers, but once you start checking if very large numbers are prime its going to slow down considerably.
One thing you can do to speed it up is only check for prime factors; ie once you've determined that number is not divisible by 3 you know its not divisible by 6, 9, 12 etc.
For very large numbers you may want to look into better methods:
http://en.wikipedia.org/wiki/Primality_test
Edit:
I forgot to mention. If you want to test if a number is evenly divisible by another number use modulus (%). If x % y is 0 then y is a factor of x.
Last edited by NullPointer; 10-23-2010 at 11:13 PM..
|