-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem-003.lisp
More file actions
33 lines (28 loc) · 970 Bytes
/
problem-003.lisp
File metadata and controls
33 lines (28 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
;;;; Problem 3
(defun problem-003 ()
(largest-prime-factor 600851475143))
(defun largest-prime-factor (n)
"Returns the largest prime factor of n."
(assert (integerp n)
(n))
(let ((factor 2)
(num n))
(if (primep num)
num
(loop until (= num factor)
do (progn
(loop while (and (zerop (mod num factor))
(not (= num factor)))
do (setf num (/ num factor)))
(unless (= num factor)
(progn
(incf factor)
(loop until (primep factor)
do (incf factor)))))))
factor))
;; (PROBLEM-003)
;; took 4,250 microseconds (0.004250 seconds) to run.
;; During that period, and with 8 available CPU cores,
;; 4,135 microseconds (0.004135 seconds) were spent in user mode
;; 34 microseconds (0.000034 seconds) were spent in system mode
;; 108,448 bytes of memory allocated.