mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Some folks might think: “you still use RCS”?!? And we will say, hey, at least we switched from SCCS to RCS back in … I think it was around 1994 ... at least we are keeping up! :-) :-) :-) Logs say that SCCS version 18 became RCS version 19 on 1994 March 18. RCS served us well. But now it is time to move on. And so we are switching to git. Calc releases produce a lot of file changes. In the 125 releases of calc since 1996, when I started managing calc releases, there have been 15473 file mods!
101 lines
3.7 KiB
Plaintext
101 lines
3.7 KiB
Plaintext
NAME
|
|
nextcand - next candidate for primeness
|
|
|
|
SYNOPSIS
|
|
nextcand(n [,count [, skip [, residue [,modulus]]]])
|
|
|
|
TYPES
|
|
n integer
|
|
count integer with absolute value less than 2^24, defaults to 1
|
|
skip integer. defaults to 1
|
|
residue integer, defaults to 0
|
|
modulus integer, defaults to 1
|
|
|
|
return integer
|
|
|
|
DESCRIPTION
|
|
If modulus is nonzero, nextcand(n, count, skip, residue, modulus)
|
|
returns the least integer i greater than abs(n) expressible as
|
|
residue + k * modulus, where k is an integer, for which
|
|
ptest(i,count,skip) == 1, or if there is no such integer, zero.
|
|
|
|
If abs(n) < 2^32, count >= 0, and the returned value i is not zero, then
|
|
i is definitely prime. If count is not zero and the returned
|
|
value i is greater than 2^32, then i is probably prime, particularly
|
|
if abs(count) > 1.
|
|
|
|
If skip == 0, and abs(n) >= 2^32 or count < 0, the probabilistic test with
|
|
random bases is used so that if n is composite the
|
|
probability that it passes ptest() is less than 4^-abs(count).
|
|
|
|
If skip == 1 (the default value), the bases used in the probabilistic
|
|
test are the first abs(count) primes 2, 3, 5, ...
|
|
|
|
For other values of skip, the bases used in the probabilistic tests
|
|
are the abs(count) consecutive integers, skip, skip + 1, skip + 2, ...
|
|
|
|
In any case, if the integer returned by nextcand() is not zero,
|
|
all integers between abs(n) and that integer are composite.
|
|
|
|
If modulus is zero, the value returned is that of residue if this is
|
|
greater than abs(n) and ptest(residue,count,skip) = 1. Otherwise
|
|
zero is returned.
|
|
|
|
RUNTIME
|
|
The runtime for v = nextcand(n, ...) will depend strongly on the
|
|
number and nature of the integers between n and v. If this number
|
|
is reasonably large the size of count is largely irrelevant as the
|
|
compositeness of the numbers between n and v will usually be
|
|
determined by the test for small prime factors or one pseudoprime
|
|
test with some base b. If N > 1, count should be positive so that
|
|
candidates divisible by small primes will be passed over quickly.
|
|
|
|
On the average for random n with large word-count N, the runtime seems
|
|
to be roughly K/N^3 some constant K.
|
|
|
|
EXAMPLE
|
|
; print nextcand(50), nextcand(112140,-2), nextcand(112140,-3)
|
|
53 112141 112153
|
|
|
|
; print nextcand(100,1,1,1,6), nextcand(100,1,1,-1,6)
|
|
103 101
|
|
|
|
; print nextcand(100,1,1,2,6), nextcand(100,1,1,303,202)
|
|
1 101
|
|
|
|
; print nextcand(2e60, 1, 1, 31, 1e30)
|
|
2000000000000000000000000000053000000000000000000000000000031
|
|
|
|
LIMITS
|
|
none
|
|
|
|
LINK LIBRARY
|
|
int znextcand(ZVALUE n, long count, long skip, ZVALUE res, ZVALUE mod,
|
|
ZVALUE *cand)
|
|
|
|
SEE ALSO
|
|
factor, isprime, lfactor, nextprime, prevcand, prevprime,
|
|
pfact, pix, ptest
|
|
|
|
## Copyright (C) 1999-2006 Landon Curt Noll
|
|
##
|
|
## Calc is open software; you can redistribute it and/or modify it under
|
|
## the terms of the version 2.1 of the GNU Lesser General Public License
|
|
## as published by the Free Software Foundation.
|
|
##
|
|
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
|
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
|
## Public License for more details.
|
|
##
|
|
## A copy of version 2.1 of the GNU Lesser General Public License is
|
|
## distributed with calc under the filename COPYING-LGPL. You should have
|
|
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
##
|
|
## Under source code control: 1996/02/25 00:27:43
|
|
## File existed as early as: 1996
|
|
##
|
|
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
|
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|