(defun main (&rest argv) (declare (ignorable argv)) (let* ((n (read)) (dp (make-array 20001 :element-type 'integer :initial-element -123)) (sieve (make-array 20001 :initial-element nil))) (setf (aref dp 0) 0) (loop for i from 2 to 20000 do (loop for j from (* i i) to 20000 by i do (setf (aref sieve j) t)) (unless (aref sieve i) (loop for j from (- 20000 i) downto 0 do (setf (aref dp (+ i j)) (max (1+ (aref dp j)) (aref dp (+ i j))))))) (format t "~d~%" (max -1 (aref dp n))))) (main)