結果

問題 No.1092 modular arithmetic
ユーザー laneguelanegue
提出日時 2020-09-07 22:59:28
言語 Crystal
(1.11.2)
結果
RE  
実行時間 -
コード長 513 bytes
コンパイル時間 17,572 ms
コンパイル使用メモリ 253,512 KB
実行使用メモリ 11,608 KB
最終ジャッジ日時 2023-09-13 12:04:38
合計ジャッジ時間 19,312 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,384 KB
testcase_01 AC 18 ms
11,532 KB
testcase_02 AC 3 ms
4,384 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 11 ms
7,868 KB
testcase_14 AC 11 ms
8,012 KB
testcase_15 AC 4 ms
5,148 KB
testcase_16 AC 9 ms
6,744 KB
testcase_17 AC 12 ms
8,004 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].to_i64
def pow_mod(a, n, m)
    r = 1_i64
    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