結果

問題 No.16 累乗の加算
ユーザー zazaboonzazaboon
提出日時 2017-02-05 18:50:45
言語 Ruby
(3.3.0)
結果
AC  
実行時間 89 ms / 5,000 ms
コード長 315 bytes
コンパイル時間 48 ms
コンパイル使用メモリ 11,404 KB
実行使用メモリ 15,204 KB
最終ジャッジ日時 2023-09-08 12:05:07
合計ジャッジ時間 2,048 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
15,204 KB
testcase_01 AC 82 ms
15,044 KB
testcase_02 AC 83 ms
15,092 KB
testcase_03 AC 82 ms
15,124 KB
testcase_04 AC 81 ms
15,180 KB
testcase_05 AC 82 ms
15,156 KB
testcase_06 AC 81 ms
15,128 KB
testcase_07 AC 81 ms
15,112 KB
testcase_08 AC 83 ms
15,192 KB
testcase_09 AC 82 ms
15,016 KB
testcase_10 AC 82 ms
15,168 KB
testcase_11 AC 83 ms
15,088 KB
testcase_12 AC 80 ms
15,176 KB
testcase_13 AC 82 ms
15,092 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:13: warning: assigned but unused variable - p
Syntax OK

ソースコード

diff #

def k2(k)
  return 1 if(k == 0)
  return $n if(k == 1)
  ans = 1
  if((k%2) == 0)
    ans *= k2(k/2)**2
  else
    ans *= k2(k-1)
    ans *= $n
  end
  return ans % $m
end
$n,p = gets.chomp.split(" ").map{|u|u.to_i}
$m = 1000003
t = gets.chomp.split(" ").map{|u|u.to_i}
a = 0
t.each do |d|
  a += k2(d)
end
p a % $m
0