結果
| 問題 |
No.16 累乗の加算
|
| コンテスト | |
| ユーザー |
Common Lisp
|
| 提出日時 | 2024-10-23 03:02:56 |
| 言語 | Common Lisp (sbcl 2.5.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 5,000 ms |
| コード長 | 769 bytes |
| コンパイル時間 | 646 ms |
| コンパイル使用メモリ | 37,524 KB |
| 実行使用メモリ | 32,016 KB |
| 最終ジャッジ日時 | 2024-10-23 03:02:58 |
| 合計ジャッジ時間 | 1,530 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 23 OCT 2024 03:02:56 AM): ; wrote /home/judge/data/code/Main.fasl ; compilation finished in 0:00:00.010
ソースコード
(defun powmod (base n &optional mo)
(labels ((rec (b e m)
(cond
((= e 0) 1)
((evenp e)
(let ((half (rec b (/ e 2) m)))
(if m
(mod (* half half) m)
(* half half))))
(t
(let ((half (rec b (/ (1- e) 2) m)))
(if m
(mod (* b (mod (* half half) m)) m)
(* b (* half half))))))))
(rec base n mo)))
(defun main (&rest argv)
(declare (ignorable argv))
(let* ((x (read))
(n (read))
(a (loop repeat n collect (read)))
(m 1000003))
(princ (mod (reduce #'+ (map 'list (lambda (f) (powmod x f m)) a)) m))
(terpri)))
(main)
Common Lisp