XP is just a number | |
PerlMonks |
Re: YAPNC: Yet another prime number checker?by Abigail-II (Bishop) |
on Oct 09, 2002 at 07:24 UTC ( [id://203850]=note: print w/replies, xml ) | Need Help?? |
This is a very inefficient algorithm. What you are doing is counting all
the divisors of a number (with the exception of divisors divisible by 5)
and call it a prime if there are just 2 divisors (special casing a few
numbers).
It's of course a lot more efficient to decide a number is prime as soon as you have found a divisor > 1 and smaller or equal to sqrt (number). No need to do millions of divisions to decide 100000000 is prime after finding out it's divisible by 2. Abigail
In Section
Seekers of Perl Wisdom
|
|