結果

問題 No.16 累乗の加算
ユーザー simansiman
提出日時 2015-04-02 21:28:53
言語 Ruby
(3.3.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 421 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 11,504 KB
実行使用メモリ 15,532 KB
最終ジャッジ日時 2023-09-08 11:35:25
合計ジャッジ時間 2,459 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:21: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

class Fixnum
  def power(x)
    result = 1
    n = self

    while x > 0
      result = (result * n) % 1_000_003 if (x & 1).nonzero?

      n = (n * n) % 1_000_003
      x >>= 1
    end

    result
  end
end

class Yukicoder
  EPS = 1_000_003

  def initialize
    x, n = gets.chomp.split(' ').map(&:to_i)
    a = gets.chomp.split(' ').map(&:to_i)

    puts a.map{|i| x.power(i)}.inject(:+) % EPS
  end
end

Yukicoder.new
0