Challenge:
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
Programming Language:
LISP
Solution:
(defun lprimefactor(num)
(loop for x in (reverse (getprimes 10000))
do (if (eql 0 (mod num x))
(format t "~a is a prime factor of ~a~%" x num))))
(defun isprime-p(n)
(defparameter isprime NIL)
(if (and (oddp n) (> n 2))
(loop for x from 2 below n
do (if (eql 0 (mod n x))
(progn (setq isprime NIL)
(return NIL))
(setq isprime T))))
(if (eq n 2)
(setq isprime T))
(print isprime))
(defun getprimes(lim)
(defparameter primes NIL)
(loop for x from 1 to lim
do (if (eql T (isprime-p x))
(push x primes)))
(print primes))
Overview:
Coming soon…