結果

問題 No.16 累乗の加算
ユーザー d_nishiyama85d_nishiyama85
提出日時 2016-06-13 04:41:02
言語 Ruby
(3.3.0)
結果
AC  
実行時間 88 ms / 5,000 ms
コード長 382 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 11,216 KB
実行使用メモリ 15,544 KB
最終ジャッジ日時 2023-09-08 11:59:36
合計ジャッジ時間 2,646 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
15,544 KB
testcase_01 AC 88 ms
15,400 KB
testcase_02 AC 86 ms
15,328 KB
testcase_03 AC 87 ms
15,412 KB
testcase_04 AC 85 ms
15,328 KB
testcase_05 AC 86 ms
15,392 KB
testcase_06 AC 86 ms
15,236 KB
testcase_07 AC 84 ms
15,416 KB
testcase_08 AC 86 ms
15,544 KB
testcase_09 AC 84 ms
15,332 KB
testcase_10 AC 84 ms
15,348 KB
testcase_11 AC 84 ms
15,420 KB
testcase_12 AC 85 ms
15,340 KB
testcase_13 AC 85 ms
15,208 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:20: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

require 'pp'

MOD = 1000003

def pow(x, a)
  if a === 0
    return 1
  end
  p = 1
  while a > 0 do
    if a % 2 > 0
      p = (p * x) % MOD
    end
    x = (x * x) % MOD
    a /= 2
  end
  return p
end

x, n = gets.strip.split.map { |e| e.to_i }
a = gets.strip.split.map { |e| e.to_i }

# pp a.map { |e|  pow(x, e)}
total = a.reduce(0){|sum, p| (sum + pow(x, p)) % MOD}
puts total
0