結果
問題 |
No.891 隣接3項間の漸化式
|
ユーザー |
![]() |
提出日時 | 2024-11-04 22:49:41 |
言語 | Common Lisp (sbcl 2.5.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 874 bytes |
コンパイル時間 | 257 ms |
コンパイル使用メモリ | 35,764 KB |
実行使用メモリ | 32,016 KB |
最終ジャッジ日時 | 2024-11-04 22:49:43 |
合計ジャッジ時間 | 2,430 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 04 NOV 2024 10:49:41 PM): ; wrote /home/judge/data/code/Main.fasl ; compilation finished in 0:00:00.021
ソースコード
(defconstant +mod107+ 1000000007) (defun %mod-mat-mul (n a b m) (let ((res (make-array `(,n ,n) :initial-element 0))) (dotimes (i n) (dotimes (j n) (dotimes (k n) (incf (aref res i j) (* (aref a i k) (aref b k j))) (setf (aref res i j) (mod (aref res i j) m))))) res)) (defun main (&rest argv) (declare (ignorable argv)) (let* ((a (read)) (b (read)) (n (read)) (A (make-array '(2 2) :initial-contents `((,a ,b) (1 0)))) (E (make-array '(2 2) :initial-contents `((1 0) (0 1)))) (m (1- n))) (when (<= n 1) (format t "~d~%" n) (return-from main)) (dotimes (i 30) (unless (zerop (logand 1 (ash m (- i)))) (setf E (%mod-mat-mul 2 A E +mod107+))) (setf A (%mod-mat-mul 2 A A +mod107+))) (format t "~d~%" (aref E 0 0)))) (main)