結果

問題 No.16 累乗の加算
コンテスト
ユーザー zazaboon
提出日時 2017-02-05 18:50:45
言語 Ruby
(4.0.1)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
AC  
実行時間 55 ms / 5,000 ms
コード長 315 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 179 ms
コンパイル使用メモリ 8,960 KB
実行使用メモリ 14,976 KB
最終ジャッジ日時 2026-03-12 19:47:15
合計ジャッジ時間 1,464 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:13: warning: assigned but unused variable - p
Syntax OK

ソースコード

diff #
raw source code

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