結果

問題 No.16 累乗の加算
ユーザー MiyamonYMiyamonY
提出日時 2019-09-05 11:14:48
言語 Scheme
(Gauche-0.9.14)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 411 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 5,292 KB
実行使用メモリ 12,984 KB
最終ジャッジ日時 2023-08-31 01:07:07
合計ジャッジ時間 2,081 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
12,724 KB
testcase_01 AC 25 ms
12,620 KB
testcase_02 AC 28 ms
12,952 KB
testcase_03 AC 26 ms
12,948 KB
testcase_04 AC 27 ms
12,712 KB
testcase_05 AC 27 ms
12,852 KB
testcase_06 AC 27 ms
12,920 KB
testcase_07 AC 28 ms
12,860 KB
testcase_08 AC 28 ms
12,888 KB
testcase_09 AC 29 ms
12,960 KB
testcase_10 AC 29 ms
12,984 KB
testcase_11 AC 26 ms
12,724 KB
testcase_12 AC 27 ms
12,888 KB
testcase_13 AC 27 ms
12,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

(define MOD 1000003)

(define (pow x n)
  (define y (mod (* x x) MOD))
  (define m (div n 2))

  (cond ((= n 0) 1)
	((= (mod n 2) 1) (mod (* x (pow y m)) MOD))
	(else
	 (pow y m))))

(let* ((pair (map string->number (string-split (read-line) #\space)))
       (x (car pair))
       (arr (map string->number (string-split (read-line) #\space))))

  (print (fold (lambda (n s) (mod (+ (pow x n) s) MOD)) 0 arr)))
0