結果
| 問題 |
No.526 フィボナッチ数列の第N項をMで割った余りを求める
|
| コンテスト | |
| ユーザー |
Common Lisp
|
| 提出日時 | 2024-10-30 12:55:34 |
| 言語 | Common Lisp (sbcl 2.5.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 2,000 ms |
| コード長 | 505 bytes |
| コンパイル時間 | 529 ms |
| コンパイル使用メモリ | 35,264 KB |
| 実行使用メモリ | 29,860 KB |
| 最終ジャッジ日時 | 2024-10-30 12:55:36 |
| 合計ジャッジ時間 | 1,677 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 30 OCT 2024 12:55:34 PM): ; file: /home/judge/data/code/Main.lisp ; in: DEFUN FIB ; (ZEROP C) ; ; note: unable to ; open-code FLOAT to RATIONAL comparison ; due to type uncertainty: ; The first argument is a NUMBER, not a SINGLE-FLOAT. ; ; note: unable to ; open-code FLOAT to RATIONAL comparison ; due to type uncertainty: ; The first argument is a NUMBER, not a DOUBLE-FLOAT. ; ; note: unable to ; open-code FLOAT to RATIONAL comparison ; due to type uncertainty: ; The first argument is a NUMBER, not a (COMPLEX SINGLE-FLOAT). ; ; note: unable to ; open-code FLOAT to RATIONAL comparison ; due to type uncertainty: ; The first argument is a NUMBER, not a (COMPLEX DOUBLE-FLOAT). ; ; note: unable to open code because: The operands might not be the same type. ; (MOD B M) ; ; note: unable to ; optimize ; due to type uncertainty: ; The first argument is a REAL, not a SINGLE-FLOAT. ; The second argument is a REAL, not a (OR SINGLE-FLOAT INTEGER). ; ; note: unable to ; optimize ; due to type uncertainty: ; The first argument is a REAL, not a DOUBLE-FLOAT. ; The second argument is a REAL, not a (OR FLOAT INTEGER). ; ; note: unable to ; optimize ; due to type uncertainty: ; The first argument is a REAL, not a INTEGER. ; The second argument is a REAL, not a INTEGER. ; (MOD (+ (* P P) (* Q Q)) M) ; ; note: unable to ; optimize ; due to type uncertainty: ; The first argument is a REAL, not a SINGLE-FLOAT. ; The second argument is a REAL, not a (OR SINGLE-FLOAT INTEGER). ; ; note: unable to ; optimize ; due to type uncertainty: ; The first argument is a REAL, not a DOUBLE-FLOAT. ; The second argument is a REAL, not a (OR FLOAT INTEGER). ; ; note: unable to ; optimize ; due to type uncertainty: ; The first argument is a REAL, not a INTEGER. ; The second argument is a REAL, not a INTEGER. ; (* 2 P Q) ; ; note: unable to ; optimize ; due to ty
ソースコード
(declaim (optimize (speed 3) (safety 0)))
(defun fib (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))
(let* ((n (read))
(m (read)))
(format t "~D~%" (fib (1- n) m))))
(main)
Common Lisp