(defconstant +mod+ 17) (defvar *tetranacci-mod17* (make-array 1000000 :element-type 'integer :initial-element 0)) (defvar *tetranacci-mod17-index* 0) (defun tetranacci-mod17-period () (setf (aref *tetranacci-mod17* 0) 1 (aref *tetranacci-mod17* 1) 0 (aref *tetranacci-mod17* 2) 0 (aref *tetranacci-mod17* 3) 0 (aref *tetranacci-mod17* 4) 1 *tetranacci-mod17-index* 5) (loop for i from 5 below 100000 do (let* ((a (aref *tetranacci-mod17* (- i 1))) (b (aref *tetranacci-mod17* (- i 2))) (c (aref *tetranacci-mod17* (- i 3))) (d (aref *tetranacci-mod17* (- i 4))) (e (mod (+ a b c d) +mod+))) (setf (aref *tetranacci-mod17* i) e) (if (and (= e 1) (= d 0) (= c 0) (= b 0) (= a 1) (/= i 5)) (progn (decf *tetranacci-mod17-index* 5) (return-from tetranacci-mod17-period)) (incf *tetranacci-mod17-index*))))) (defun main (&rest argv) (declare (ignorable argv)) (tetranacci-mod17-period) (let* ((query (read))) (dotimes (_ query) (format t "~d~%" (aref *tetranacci-mod17* (mod (read) *tetranacci-mod17-index*)))))) (main)