結果

問題 No.16 累乗の加算
ユーザー DialBirdDialBird
提出日時 2017-02-12 19:32:13
言語 Ruby
(3.3.0)
結果
AC  
実行時間 92 ms / 5,000 ms
コード長 440 bytes
コンパイル時間 47 ms
コンパイル使用メモリ 11,548 KB
実行使用メモリ 23,208 KB
最終ジャッジ日時 2023-09-08 12:05:17
合計ジャッジ時間 2,107 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
23,116 KB
testcase_01 AC 86 ms
22,968 KB
testcase_02 AC 87 ms
23,116 KB
testcase_03 AC 89 ms
22,932 KB
testcase_04 AC 86 ms
23,208 KB
testcase_05 AC 91 ms
22,996 KB
testcase_06 AC 88 ms
23,192 KB
testcase_07 AC 86 ms
22,932 KB
testcase_08 AC 86 ms
23,084 KB
testcase_09 AC 86 ms
23,180 KB
testcase_10 AC 86 ms
23,100 KB
testcase_11 AC 88 ms
23,196 KB
testcase_12 AC 87 ms
23,180 KB
testcase_13 AC 89 ms
23,148 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

x, N = gets.chomp.split.map(&:to_i)
@devider = 1000003
list = gets.chomp.split.map{ |i| i.to_i % (@devider - 1) }

dp = Array.new(@devider, -1)

x %= @devider

def my_pow(n, idx)
  res = 1
  if idx > 0
    res = my_pow(n*n % @devider, idx/2)
    res = res * n % @devider if idx & 1 == 1
  end
  return res % @devider
end

result = 0
list.each do |l|
  if dp[l] == -1
    dp[l] = my_pow(x, l)
  end
  result += dp[l]
end

p result % @devider
0