(defconstant +mod1+ 1000000007) (defconstant +mod2+ 2000000016) (defun %mod-fibonacci (n m) (labels ((rec (a b c p q) (cond ((zerop c) (mod b m)) ((evenp c) (rec a b (floor c 2) (mod (+ (* p p) (* q q)) m) (mod (+ (* 2 p q) (* q q)) m))) (t (rec (mod (+ (* b q) (* a q) (* a p)) m) (mod (+ (* b p) (* a q)) m) (1- c) p q))))) (rec 1 0 n 0 1))) (defun main (&rest argv) (declare (ignorable argv)) (format t "~d~%" (%mod-fibonacci (%mod-fibonacci (read) +mod2+) +mod1+))) (main)