結果

問題 No.1578 A × B × C
ユーザー n_get
提出日時 2021-08-13 14:56:06
言語 Scheme
(Gauche-0.9.15)
結果
MLE  
実行時間 -
コード長 509 bytes
コンパイル時間 38 ms
コンパイル使用メモリ 6,948 KB
実行使用メモリ 819,716 KB
最終ジャッジ日時 2024-10-03 05:15:58
合計ジャッジ時間 2,127 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 MLE * 1 -- * 1
other -- * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

(define (expt-mod a n)
  (let loop ([k 1] [ak a] [ls '()]) ;; a^1 a^2 a^4のリスト
    (if (<= k n)
        (loop (* k 2) (remainder (* ak ak) 1000000007)
              (cons (cons k ak) ls))
        (let loop2 ([ls ls] [n n] [an 1])
          (cond
           [(zero? n) an]
           [(> (caar ls) n) (loop2 (cdr ls) n an)]
           [else (loop2 (cdr ls) (- n (caar ls))
                        (remainder (* an (cdar ls)) 1000000007))])))))
(print (expt-mod (* (read) (read) (read)) (expt 2 (read))))
0