結果

問題 No.2117 中国剰余定理入門
ユーザー qqspeed20015qqspeed20015
提出日時 2022-11-06 21:58:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 702 bytes
コンパイル時間 2,849 ms
コンパイル使用メモリ 164,312 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-27 15:09:20
合計ジャッジ時間 4,462 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 RE -
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 RE -
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 RE -
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int inv(int a, int m)
{
    int m0 = m, t, q;
    int x0 = 0, x1 = 1;
    if (m == 1)
        return 0;
    while (a > 1) {
        q = a / m;
        t = m;
        m = a % m, a = t;
        t = x0;
        x0 = x1 - q * x0;
        x1 = t;
    }
    if (x1 < 0)
        x1 += m0;
    return x1;
}

int main() {
    int b0, c0, b1, c1;
    scanf("%d %d %d %d", &b0, &c0, &b1, &c1);
    while (c0 < 0)
        c0 += b0;
    while (c1 < 0)
        c1 += b1;
    if (abs(c1 - c0) % __gcd(b1, b0) != 0)
        cout << "NaN";
    else {
        int res = (c0 * b1 * inv(b1, b0) + c1 * b0 * inv(b0, b1)) % (b0 * b1);
        cout << res;
    }
    return 0;
}
0