diff options
| author | Mistivia <i@mistivia.com> | 2024-11-09 23:49:08 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2024-11-09 23:49:08 +0800 |
| commit | e685ad97fa257e2d6186eab66dc151f02ddc698c (patch) | |
| tree | ceb256a537156c8ff4394a04f76c4e11c4cb89d7 | |
| parent | 37be9418ad8f5bbde5f7b703115a2d4fb5d6185e (diff) | |
3 Largest Prime Factor
| -rw-r--r-- | 0003/main.lisp | 16 |
1 files changed, 16 insertions, 0 deletions
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)) + |
