結果

問題 No.16 累乗の加算
ユーザー letrangerjpletrangerjp
提出日時 2017-06-01 22:13:56
言語 Ruby
(3.3.0)
結果
AC  
実行時間 86 ms / 5,000 ms
コード長 239 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 11,572 KB
実行使用メモリ 15,268 KB
最終ジャッジ日時 2023-09-08 12:08:56
合計ジャッジ時間 2,137 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
15,020 KB
testcase_01 AC 81 ms
15,132 KB
testcase_02 AC 83 ms
15,068 KB
testcase_03 AC 84 ms
15,252 KB
testcase_04 AC 83 ms
15,104 KB
testcase_05 AC 85 ms
15,044 KB
testcase_06 AC 82 ms
15,116 KB
testcase_07 AC 85 ms
15,044 KB
testcase_08 AC 83 ms
15,260 KB
testcase_09 AC 84 ms
15,192 KB
testcase_10 AC 83 ms
15,268 KB
testcase_11 AC 83 ms
15,152 KB
testcase_12 AC 85 ms
15,188 KB
testcase_13 AC 84 ms
15,068 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def f(a, b)
  case b
  when 0; 1
  when 1; a
  else
    c, d = b.divmod(2)
    f(a * a % MOD, c) * f(a, d)
  end
end

X, N = gets.split.take(2).map(&:to_i)
A = gets.split.take(N).map(&:to_i)
MOD = 1_000_003
p A.map{|a| f(X, a) }.sum % MOD
0