結果

問題 No.1092 modular arithmetic
ユーザー laneguelanegue
提出日時 2020-06-26 00:50:31
言語 Crystal
(1.11.2)
結果
AC  
実行時間 458 ms / 2,000 ms
コード長 562 bytes
コンパイル時間 19,344 ms
コンパイル使用メモリ 262,412 KB
実行使用メモリ 12,736 KB
最終ジャッジ日時 2023-09-13 10:50:15
合計ジャッジ時間 25,528 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,772 KB
testcase_01 AC 19 ms
11,752 KB
testcase_02 AC 3 ms
4,880 KB
testcase_03 AC 145 ms
12,560 KB
testcase_04 AC 118 ms
9,964 KB
testcase_05 AC 128 ms
10,016 KB
testcase_06 AC 93 ms
10,048 KB
testcase_07 AC 111 ms
10,032 KB
testcase_08 AC 123 ms
12,564 KB
testcase_09 AC 117 ms
10,120 KB
testcase_10 AC 99 ms
10,064 KB
testcase_11 AC 112 ms
12,320 KB
testcase_12 AC 96 ms
10,028 KB
testcase_13 AC 17 ms
8,620 KB
testcase_14 AC 20 ms
10,500 KB
testcase_15 AC 6 ms
6,020 KB
testcase_16 AC 14 ms
8,000 KB
testcase_17 AC 20 ms
10,636 KB
testcase_18 AC 154 ms
12,736 KB
testcase_19 AC 93 ms
10,044 KB
testcase_20 AC 157 ms
12,728 KB
testcase_21 AC 122 ms
10,148 KB
testcase_22 AC 150 ms
12,576 KB
testcase_23 AC 398 ms
12,504 KB
testcase_24 AC 113 ms
6,920 KB
testcase_25 AC 300 ms
8,432 KB
testcase_26 AC 343 ms
12,440 KB
testcase_27 AC 57 ms
5,500 KB
testcase_28 AC 292 ms
10,132 KB
testcase_29 AC 458 ms
12,648 KB
testcase_30 AC 305 ms
10,136 KB
testcase_31 AC 42 ms
5,568 KB
testcase_32 AC 278 ms
8,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

require "big"
pr, n = read_line.split.map{|i|i.to_i64}
a = read_line.split.map{|i|i.to_i64}
s = read_line
r = a[0].to_i64
def pow_mod(a, n, m)
    r = BigInt.new(1)
    a = BigInt.new(a)
    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