結果

問題 No.487 2017 Calculation(2017の計算)
ユーザー hebiyanhebiyan
提出日時 2017-05-23 14:48:20
言語 Scheme
(Gauche-0.9.13)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 388 bytes
コンパイル時間 73 ms
コンパイル使用メモリ 5,336 KB
実行使用メモリ 17,160 KB
最終ジャッジ日時 2023-10-19 15:30:40
合計ジャッジ時間 1,321 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
17,160 KB
testcase_01 AC 33 ms
17,160 KB
testcase_02 AC 32 ms
17,160 KB
testcase_03 AC 31 ms
17,160 KB
testcase_04 AC 32 ms
17,160 KB
testcase_05 AC 32 ms
17,160 KB
testcase_06 AC 32 ms
17,160 KB
testcase_07 AC 32 ms
17,160 KB
testcase_08 AC 32 ms
17,160 KB
testcase_09 AC 32 ms
17,160 KB
testcase_10 AC 31 ms
17,160 KB
testcase_11 AC 32 ms
17,160 KB
testcase_12 AC 31 ms
17,160 KB
testcase_13 AC 35 ms
17,160 KB
testcase_14 AC 33 ms
17,160 KB
testcase_15 AC 32 ms
17,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

(define (powmod b p m)
  (cond
   ((zero? p) 1)
   ((zero? b) 0)
   (else
    (if (zero? (mod p 2))
        (letrec ((prev (powmod b (div p 2) m)))
          (mod (* prev prev) m))
        (letrec ((prev (powmod b (- p 1) m)))
          (mod (* b prev) m))))))

(define (answer m)
  (mod (+ (mod 2017 m)
          (powmod (* 2017 2017) 2017 m))
       m))
       
(print (answer (read)))
0