結果

問題 No.16 累乗の加算
ユーザー wotsushiwotsushi
提出日時 2017-02-26 17:27:59
言語 Ruby
(3.3.0)
結果
AC  
実行時間 82 ms / 5,000 ms
コード長 262 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 11,420 KB
実行使用メモリ 15,316 KB
最終ジャッジ日時 2023-09-08 12:05:27
合計ジャッジ時間 2,009 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,316 KB
testcase_01 AC 78 ms
15,236 KB
testcase_02 AC 80 ms
15,184 KB
testcase_03 AC 80 ms
15,156 KB
testcase_04 AC 78 ms
15,044 KB
testcase_05 AC 82 ms
15,240 KB
testcase_06 AC 81 ms
15,312 KB
testcase_07 AC 81 ms
15,208 KB
testcase_08 AC 80 ms
15,316 KB
testcase_09 AC 80 ms
15,312 KB
testcase_10 AC 81 ms
15,124 KB
testcase_11 AC 80 ms
15,132 KB
testcase_12 AC 79 ms
15,288 KB
testcase_13 AC 79 ms
15,180 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

M = 1000003
x, N = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
def f(i, x)
  t = i
  y = 1
  z = x
  while t > 0
    if t % 2 == 1
      y = (y * z) % M
    end
    z = (z * z) % M
    t /= 2
  end
  y
end
ans = a.map {|i| f(i, x)}.inject(:+) % M
puts ans
0