diff --git a/lib/chibi/math/prime.scm b/lib/chibi/math/prime.scm index 701d1ef7..65ba56e3 100644 --- a/lib/chibi/math/prime.scm +++ b/lib/chibi/math/prime.scm @@ -171,15 +171,14 @@ (list n)) (else (let lp ((n n) - (limit (exact (ceiling (sqrt n)))) (res (list))) (cond ((even? n) - (lp (quotient n 2) (quotient limit 2) (cons 2 res))) + (lp (quotient n 2) (cons 2 res))) ((= n 1) (reverse res)) (else - (let lp ((i 3) (n n) (limit limit) (res res)) + (let lp ((i 3) (n n) (limit (exact (ceiling (sqrt n)))) (res res)) (cond ((= n 1) (reverse res)) diff --git a/tests/prime-tests.scm b/tests/prime-tests.scm index 540c3ab0..a060f82c 100644 --- a/tests/prime-tests.scm +++ b/tests/prime-tests.scm @@ -68,6 +68,8 @@ (test '(2 5) (factor 10)) (test '(11) (factor 11)) (test '(2 2 3) (factor 12)) +(test '(2 3 3) (factor 18)) +(test '(2 2 2 3 3) (factor 72)) (test '(3 3 3 5 7) (factor 945)) (test 975 (aliquot 945))