結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー testtest
提出日時 2022-11-25 06:05:59
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 233 ms / 2,000 ms
コード長 493 bytes
コンパイル時間 206 ms
コンパイル使用メモリ 6,948 KB
実行使用メモリ 43,520 KB
最終ジャッジ日時 2024-04-09 04:30:27
合計ジャッジ時間 2,550 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
39,040 KB
testcase_01 AC 61 ms
39,168 KB
testcase_02 AC 62 ms
39,168 KB
testcase_03 AC 63 ms
39,040 KB
testcase_04 AC 62 ms
39,040 KB
testcase_05 AC 62 ms
39,168 KB
testcase_06 AC 63 ms
39,168 KB
testcase_07 AC 62 ms
39,168 KB
testcase_08 AC 62 ms
39,168 KB
testcase_09 AC 67 ms
43,008 KB
testcase_10 AC 86 ms
42,752 KB
testcase_11 AC 231 ms
43,520 KB
testcase_12 AC 108 ms
42,752 KB
testcase_13 AC 233 ms
43,520 KB
testcase_14 AC 106 ms
42,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

function Main(input) {
    const src = input.replace("\n", "").split(" ");
    const n = parseInt(src[0]);
    const m = parseInt(src[1]);
    let ans = 0;
    if (n < 3) {
        ans = (n == 1 ? 0 : 1 % m);
    } else {
        let a = 0;
        let b = 1;
        let c = 1;
        for (i = 3; i <= n; i++) {
            c = (a + b) % m;
            a = b;
            b = c;
        }
        ans = c;
    }
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
0