結果

問題 No.2117 中国剰余定理入門
ユーザー testtest
提出日時 2022-11-20 05:50:42
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 725 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 5,332 KB
実行使用メモリ 41,224 KB
最終ジャッジ日時 2023-10-21 07:19:38
合計ジャッジ時間 3,439 ms
ジャッジサーバーID
(参考情報)
judge13 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
37,480 KB
testcase_01 AC 61 ms
37,480 KB
testcase_02 AC 65 ms
37,480 KB
testcase_03 AC 64 ms
37,480 KB
testcase_04 AC 65 ms
37,480 KB
testcase_05 AC 65 ms
37,480 KB
testcase_06 AC 66 ms
37,480 KB
testcase_07 AC 65 ms
37,480 KB
testcase_08 AC 65 ms
37,480 KB
testcase_09 AC 63 ms
37,480 KB
testcase_10 AC 65 ms
37,448 KB
testcase_11 AC 63 ms
37,448 KB
testcase_12 AC 64 ms
37,448 KB
testcase_13 AC 65 ms
37,448 KB
testcase_14 AC 61 ms
37,448 KB
testcase_15 AC 64 ms
37,448 KB
testcase_16 AC 63 ms
37,448 KB
testcase_17 AC 131 ms
41,224 KB
testcase_18 AC 66 ms
37,496 KB
testcase_19 AC 63 ms
37,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

function calcCRT(B0, C0, B1, C1) {
    C0 = (C0 >= 0 ? C0 % B0 : (B0 - (- C0) % B0) % B0);
    C1 = (C1 >= 0 ? C1 % B1 : (B1 - (- C1) % B1) % B1);
    let product = B0 * B1;
    for (let n = 0; n < product; n++) {
        if (n % B0 == C0 && n % B1 == C1) {
            return n.toString();
        }
    }
    return "NaN";
}

function Main(input) {
    let src = input.replace("\n", " ").split(" ");
    let B0 = parseInt(src[0]);
    let C0 = parseInt(src[1]);
    let B1 = parseInt(src[2]);
    let C1 = parseInt(src[3]);
    console.log(calcCRT(B0, C0, B1, C1));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// ※数学的アルゴリズムは理解出来ないので、解説の模範解答を移植のみ
0