結果

問題 No.2117 中国剰余定理入門
ユーザー testtest
提出日時 2022-11-20 05:47:40
言語 JavaScript
(node v21.7.1)
結果
WA  
実行時間 -
コード長 723 bytes
コンパイル時間 32 ms
コンパイル使用メモリ 5,152 KB
実行使用メモリ 41,344 KB
最終ジャッジ日時 2023-10-21 07:17:46
合計ジャッジ時間 3,381 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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