2 factor - smallest prime factor not exceeding specified limit
5 factor(n [, limit [, err]])
9 limit integer with abs(limit) < 2^32, defaults to 2^32 - 1
12 return positive integer or err
15 This function ignores the signs of n and limit, so here we shall
16 assume n and limit are both nonnegative.
18 If n has a prime proper factor less than or equal to limit, then
19 factor(n, limit) returns the smallest such factor.
21 NOTE: A proper factor of n>1 is a factor < n. In other words,
22 for n>1 is not a proper factor of itself. The value 1
23 is a special case because 1 is a proper factor of 1.
25 When every prime proper factor of n is greater than limit, 1 is
26 returned. In particular, if limit < 2, factor(n, limit) always
27 returns 1. Also, factor(n,2) returns 2 if and only if n is even
30 If 1 < n < nextprime(limit)^2, then f(n, limit) == 1 <==> n is prime.
31 For example, if 1 < n < 121, n is prime if and only if f(n,7) == 1.
33 If limit >= 2^32, factor(n, limit) causes an error and factor(n,
34 limit, err) returns the value of err.
37 ; print factor(35,4), factor(35,5), factor(35), factor(-35)
40 ; print factor(2^32 + 1), factor(2^47 - 1), factor(2^59 - 1)
47 FLAG zfactor(ZVALUE n, ZVALUE limit, ZVALUE *res)
50 isprime, lfactor, nextcand, nextprime, prevcand, prevprime,
53 ## Copyright (C) 1999-2006 Landon Curt Noll
55 ## Calc is open software; you can redistribute it and/or modify it under
56 ## the terms of the version 2.1 of the GNU Lesser General Public License
57 ## as published by the Free Software Foundation.
59 ## Calc is distributed in the hope that it will be useful, but WITHOUT
60 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
61 ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
62 ## Public License for more details.
64 ## A copy of version 2.1 of the GNU Lesser General Public License is
65 ## distributed with calc under the filename COPYING-LGPL. You should have
66 ## received a copy with calc; if not, write to Free Software Foundation, Inc.
67 ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
69 ## @(#) $Revision: 30.1 $
70 ## @(#) $Id: factor,v 30.1 2007/03/16 11:10:42 chongo Exp $
71 ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/factor,v $
73 ## Under source code control: 1995/12/18 12:34:57
74 ## File existed as early as: 1995
76 ## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
77 ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/