結果

問題 No.1092 modular arithmetic
ユーザー face4face4
提出日時 2020-07-05 13:27:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 703 bytes
コンパイル時間 706 ms
コンパイル使用メモリ 64,964 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 14:50:50
合計ジャッジ時間 6,588 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 48 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 68 ms
4,348 KB
testcase_04 AC 57 ms
4,348 KB
testcase_05 AC 58 ms
4,348 KB
testcase_06 AC 42 ms
4,348 KB
testcase_07 AC 54 ms
4,348 KB
testcase_08 AC 60 ms
4,348 KB
testcase_09 AC 55 ms
4,348 KB
testcase_10 AC 47 ms
4,348 KB
testcase_11 AC 53 ms
4,348 KB
testcase_12 AC 44 ms
4,348 KB
testcase_13 AC 18 ms
4,348 KB
testcase_14 AC 20 ms
4,348 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 AC 16 ms
4,348 KB
testcase_17 AC 21 ms
4,348 KB
testcase_18 AC 70 ms
4,348 KB
testcase_19 AC 43 ms
4,348 KB
testcase_20 AC 73 ms
4,348 KB
testcase_21 AC 56 ms
4,348 KB
testcase_22 AC 68 ms
4,348 KB
testcase_23 AC 112 ms
4,348 KB
testcase_24 AC 33 ms
4,348 KB
testcase_25 AC 83 ms
4,348 KB
testcase_26 AC 96 ms
4,348 KB
testcase_27 AC 17 ms
4,348 KB
testcase_28 AC 80 ms
4,348 KB
testcase_29 AC 127 ms
4,348 KB
testcase_30 AC 83 ms
4,348 KB
testcase_31 AC 12 ms
4,348 KB
testcase_32 AC 78 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

typedef long long ll;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

int main(){
    int p, n;
    cin >> p >> n;
    int a[n];
    for(int i = 0; i < n; i++)  cin >> a[i];
    ll ans = a[0];
    for(int i = 1; i < n; i++){
        char c;
        cin >> c;
        if(c == '+')    (ans += a[i]) %= p;
        if(c == '-')    (ans += p-a[i]) %= p;
        if(c == '*')    (ans *= a[i]) %= p;
        if(c == '/')    (ans *= modpow(a[i], p-2, p)) %= p;
    }
    cout << ans << endl;
    return 0;
}
0