結果

問題 No.1092 modular arithmetic
ユーザー lanegue
提出日時 2020-06-26 00:10:51
言語 Crystal
(1.14.0)
結果
RE  
実行時間 -
コード長 503 bytes
コンパイル時間 11,091 ms
コンパイル使用メモリ 296,336 KB
実行使用メモリ 9,472 KB
最終ジャッジ日時 2024-06-30 20:19:25
合計ジャッジ時間 12,819 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 6 RE * 26
権限があれば一括ダウンロードができます

ソースコード

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