結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー nebukuro09nebukuro09
提出日時 2017-06-09 22:25:12
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 486 bytes
コンパイル時間 882 ms
コンパイル使用メモリ 100,924 KB
実行使用メモリ 43,068 KB
最終ジャッジ日時 2023-09-03 14:06:35
合計ジャッジ時間 2,453 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 23 ms
9,908 KB
testcase_11 AC 105 ms
42,692 KB
testcase_12 AC 105 ms
43,068 KB
testcase_13 AC 104 ms
42,032 KB
testcase_14 AC 105 ms
42,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

immutable long MOD = 10^^9+7;

void main() {
    auto s = readln.split;
    auto N = s[0].to!int;
    auto M = s[1].to!long;

    auto F = new long[](N+1);
    F[0] = 0;
    F[1] = 0;
    F[2] = 1;
    foreach (i; 3..N+1) {
        F[i] = (F[i-1] + F[i-2]) % M;
    }

    F[N].writeln;
}
0