結果

問題 No.1092 modular arithmetic
ユーザー laneguelanegue
提出日時 2020-06-26 00:10:51
言語 Crystal
(1.11.2)
結果
RE  
実行時間 -
コード長 503 bytes
コンパイル時間 20,414 ms
コンパイル使用メモリ 253,196 KB
実行使用メモリ 11,784 KB
最終ジャッジ日時 2023-09-13 10:49:43
合計ジャッジ時間 20,211 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,504 KB
testcase_01 RE -
testcase_02 AC 2 ms
4,432 KB
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 AC 10 ms
8,064 KB
testcase_14 AC 12 ms
7,980 KB
testcase_15 AC 5 ms
5,192 KB
testcase_16 AC 9 ms
6,784 KB
testcase_17 AC 10 ms
7,840 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

pr, n = read_line.split.map{|i|i.to_i}
a = read_line.split.map{|i|i.to_i}
s = read_line
r = a[0]
def pow_mod(a, n, m)
    r = 1
    while n > 0
        if n % 2 == 1
            r *= a
            r %= m
        end
        a **= 2
        a %= m
        n >>= 1
    end
    r
end
(n - 1).times{|i|
    case s[i]
    when '+'
        r += a[i + 1]
    when '-'
        r -= a[i + 1]
    when '*'
        r *= a[i + 1]
    when '/'
        r *= pow_mod(a[i + 1], pr - 2, pr)
    end
    r %= pr
}
puts r
0