Re: How to find the next prime number?
- From: "KBH" <KBH@xxxxxxxxxxx>
- Date: Thu, 14 Sep 2006 01:31:08 -0400
For a proven prime it is dynamic enough. Take i as even and divide i + 1
by all odd numbers less than the square root of i + 1. If any division has
a zero remainder then i + 1 is not prime. And if i + 1 is not prime then
move to i + 3 and begin again.
Actually i + 1 only needs to be divided by primes less than its square
root but the overhead of producing those primes is too much unless a range
of primes greater than i is needed.
But if a range of primes greater than i is needed such as all primes from
i + 1 in steps of 2 to i + 499 then divide i + 1 by 3, take the integer
part of that result, add 2 to it, multiply by the 3, check to see if that
result is greater than i + 499, if not add another 2 and multiply by the
3 again, and continue until greater than i + 499 with each mulitplication
result between i and i + 499 clearing out a possible odd in an existing
array. Next move to the 5, begin again, and continue the overall process
up to the square root of i + 499...
http://www.kbhscape.com/prime.htm
Actually, I put the odd composites into an empty array (without sorting)
and then work with the un-assigned elements of the array as the primes...
Actually, I put the odd composites into correct position of an empty array
(without the workload of a traditional sort) and then work with the
un-assigned elements of the array as the primes...
.
- References:
- How to find the next prime number?
- From: Digital Puer
- Re: How to find the next prime number?
- From: KBH
- How to find the next prime number?
- Prev by Date: Re: roots of function
- Next by Date: Re: simplex, polyhedron
- Previous by thread: Re: How to find the next prime number?
- Next by thread: Re: How to find the next prime number?
- Index(es):
Relevant Pages
|