From e685ad97fa257e2d6186eab66dc151f02ddc698c Mon Sep 17 00:00:00 2001 From: Mistivia Date: Sat, 9 Nov 2024 23:49:08 +0800 Subject: 3 Largest Prime Factor --- 0003/main.lisp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 0003/main.lisp diff --git a/0003/main.lisp b/0003/main.lisp new file mode 100644 index 0000000..b2ba414 --- /dev/null +++ b/0003/main.lisp @@ -0,0 +1,16 @@ +(defun my-reduce (x y) + (if (= 0 (mod x y)) + (my-reduce (/ x y) y) + x)) + +(defun max-factor-impl (x cur) + (let ((next-x (my-reduce x cur))) + (if (= 1 next-x) + cur + (max-factor-impl next-x (+ 1 cur))))) + +(defun max-factor (x) + (max-factor-impl x 2)) + +(format t "~&~S~%" (max-factor 600851475143)) + -- cgit v1.0