結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー mlpj56dmlpj56d
提出日時 2017-06-18 23:19:17
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 215 ms / 2,000 ms
コード長 656 bytes
コンパイル時間 31 ms
コンパイル使用メモリ 5,376 KB
実行使用メモリ 42,752 KB
最終ジャッジ日時 2024-04-21 01:43:37
合計ジャッジ時間 2,044 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
38,912 KB
testcase_01 AC 59 ms
38,656 KB
testcase_02 AC 58 ms
38,656 KB
testcase_03 AC 58 ms
38,656 KB
testcase_04 AC 57 ms
38,656 KB
testcase_05 AC 59 ms
38,784 KB
testcase_06 AC 57 ms
38,912 KB
testcase_07 AC 57 ms
38,656 KB
testcase_08 AC 63 ms
38,528 KB
testcase_09 AC 63 ms
42,240 KB
testcase_10 AC 84 ms
42,240 KB
testcase_11 AC 215 ms
42,752 KB
testcase_12 AC 91 ms
42,496 KB
testcase_13 AC 215 ms
42,752 KB
testcase_14 AC 95 ms
42,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

function Main (input) {

  var line  = input.split(' ');
    var n = parseInt(line[0]);
    var m = parseInt(line[1]);
    fib(n,m);
}

function fib (n,m){
    var a = 0;
    var b = 1;
    var c = (a + b) % m;

if (n <= 3 ) {
   switch (n) {
       case 1: 
            console.log(a)
            break;
       case 2:
            console.log(b)
            break;
       case 3:
            console.log(c)
            break;
       default:
            break;
    }
} else {
    for (i = 4 ; i <= n; i++) {
        a = b ;
        b = c ;
        c = (a + b) % m ;
    }
	    console.log(c);
	}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
0