(defun %mod-expt (a n m) (let ((result 1)) (loop while (> n 0) when (oddp n) do (setq result (mod (* result a) m)) do (setq a (mod (* a a) m)) (setq n (ash n -1))) result)) (defun main (&rest argv) (declare (ignorable argv)) (let* ((m (read)) (f (lambda (x) (mod (+ 2017 (%mod-expt (* 2017 2017) 2017 x)) x)))) (format t "~d~%" (funcall f m)))) (main)