[libmath-prime-util-perl] 48/181: New factor_exp function
Partha P. Mukherjee
ppm-guest at moszumanska.debian.org
Thu May 21 18:51:05 UTC 2015
This is an automated email from the git hooks/post-receive script.
ppm-guest pushed a commit to annotated tag v0.36
in repository libmath-prime-util-perl.
commit 690a97ff9c7d38a33c386faaacb83c1bb2d48b66
Author: Dana Jacobsen <dana at acm.org>
Date: Fri Dec 27 18:15:05 2013 -0800
New factor_exp function
---
factor.c | 31 ++++++++++++++++++++-----------
factor.h | 1 +
2 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/factor.c b/factor.c
index 6da205a..4e0c337 100644
--- a/factor.c
+++ b/factor.c
@@ -132,6 +132,25 @@ int factor(UV n, UV *factors)
return nfactors;
}
+int factor_exp(UV n, UV *factors, UV* exponents)
+{
+ int i, j, nfactors = factor(n, factors);
+
+ if (n == 1) return 0;
+ exponents[0] = 1;
+ for (i = 1, j = 1; i < nfactors; i++) {
+ if (factors[i] != factors[i-1]) {
+ exponents[j] = 1;
+ factors[j++] = factors[i];
+ } else {
+ exponents[j-1]++;
+ }
+ }
+ return j;
+}
+
+
+
static const unsigned short primes_small[] =
{0,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,
101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,
@@ -330,17 +349,7 @@ UV* _divisor_list(UV n, UV *num_divisors)
return divs;
}
/* Factor and convert to factor/exponent pair */
- nfactors = factor(n, factors);
- exponents[0] = 1;
- for (i = 1, j = 1; i < nfactors; i++) {
- if (factors[i] != factors[i-1]) {
- exponents[j] = 1;
- factors[j++] = factors[i];
- } else {
- exponents[j-1]++;
- }
- }
- nfactors = j;
+ nfactors = factor_exp(n, factors, exponents);
/* Calculate number of divisors, allocate space, fill with divisors */
ndivisors = exponents[0] + 1;
for (i = 1; i < nfactors; i++)
diff --git a/factor.h b/factor.h
index 862fb65..41cf3c5 100644
--- a/factor.h
+++ b/factor.h
@@ -6,6 +6,7 @@
#define MPU_MAX_FACTORS 64
extern int factor(UV n, UV *factors);
+extern int factor_exp(UV n, UV *factors, UV* exponents);
extern int trial_factor(UV n, UV *factors, UV maxtrial);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git
More information about the Pkg-perl-cvs-commits
mailing list