結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,200 KB
testcase_01 AC 81 ms
15,128 KB
testcase_02 AC 80 ms
15,036 KB
testcase_03 AC 79 ms
15,080 KB
testcase_04 AC 81 ms
15,076 KB
testcase_05 AC 80 ms
15,264 KB
testcase_06 AC 81 ms
15,120 KB
testcase_07 AC 80 ms
15,300 KB
testcase_08 AC 79 ms
15,116 KB
testcase_09 AC 79 ms
15,196 KB
testcase_10 AC 79 ms
15,016 KB
testcase_11 AC 79 ms
15,048 KB
testcase_12 AC 80 ms
15,124 KB
testcase_13 AC 78 ms
15,312 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:13: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

def powm(x, q, mod=1000000007)
    y=1
    x=x%mod
    while (0<q)
        y=(y*x)%mod if q%2==1
        x=(x*x)%mod
        q/=2
    end
    return y
end

x,n = gets.split.map! &:to_i
aa = gets.split.map! &:to_i

p aa.inject(0){|s,e| (s+powm(x,e,1000003))%1000003} # <- (゚д゚)(゚д゚)
0