[libmath-prime-util-perl] 30/54: Small totient speedup
Partha P. Mukherjee
ppm-guest at moszumanska.debian.org
Thu May 21 18:52:09 UTC 2015
This is an automated email from the git hooks/post-receive script.
ppm-guest pushed a commit to annotated tag v0.38
in repository libmath-prime-util-perl.
commit 141a8de526660972d4884099b98a6fa842585f5d
Author: Dana Jacobsen <dana at acm.org>
Date: Fri Feb 14 11:51:44 2014 -0800
Small totient speedup
---
util.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/util.c b/util.c
index 2485e87..a85ee4b 100644
--- a/util.c
+++ b/util.c
@@ -1112,8 +1112,12 @@ int kronecker_ss(IV a, IV b) {
UV totient(UV n) {
UV i, nfacs, totient, lastf, facs[MPU_MAX_FACTORS+1];
if (n <= 1) return n;
- nfacs = factor(n, facs);
totient = 1;
+ /* phi(2m) = 2phi(m) if m even, phi(m) if m odd */
+ while ((n & 0x3) == 0) { n >>= 1; totient <<= 1; }
+ if ((n & 0x1) == 0) { n >>= 1; }
+ /* factor and calculate totient */
+ nfacs = factor(n, facs);
lastf = 0;
for (i = 0; i < nfacs; i++) {
UV f = facs[i];
--
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