about summary refs log tree commit diff
path: root/others/mHoang/pfactor.scm
diff options
context:
space:
mode:
Diffstat (limited to 'others/mHoang/pfactor.scm')
-rw-r--r--others/mHoang/pfactor.scm9
1 files changed, 9 insertions, 0 deletions
diff --git a/others/mHoang/pfactor.scm b/others/mHoang/pfactor.scm
new file mode 100644
index 0000000..4e3bd17
--- /dev/null
+++ b/others/mHoang/pfactor.scm
@@ -0,0 +1,9 @@
+(define (div dividend divisor)
+  (if (= (remainder dividend divisor) 0)
+      (div (/ dividend divisor) divisor)
+      dividend))
+(display (let* ((n (read)) (s (exact-integer-sqrt n)))
+           (do ((i 2 (+ i 1)))
+               ((or (= (div n i) 1) (> i s)) (if (> i s) n i))
+             (set! n (div n i)))))
+(newline)