結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー samplelpmassamplelpmas
提出日時 2017-06-10 11:23:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 228 ms / 2,000 ms
コード長 418 bytes
コンパイル時間 2,018 ms
コンパイル使用メモリ 78,796 KB
実行使用メモリ 99,508 KB
最終ジャッジ日時 2023-10-24 20:24:40
合計ジャッジ時間 4,804 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
57,604 KB
testcase_01 AC 120 ms
57,464 KB
testcase_02 AC 122 ms
57,644 KB
testcase_03 AC 112 ms
56,272 KB
testcase_04 AC 120 ms
57,568 KB
testcase_05 AC 111 ms
54,184 KB
testcase_06 AC 121 ms
57,468 KB
testcase_07 AC 121 ms
57,352 KB
testcase_08 AC 121 ms
57,400 KB
testcase_09 AC 123 ms
57,460 KB
testcase_10 AC 145 ms
63,596 KB
testcase_11 AC 224 ms
99,508 KB
testcase_12 AC 223 ms
99,480 KB
testcase_13 AC 228 ms
99,480 KB
testcase_14 AC 223 ms
99,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();

        long F[] = new long[N + 1];

        F[1] = 0;
        F[2] = 1;

        for (int i = 3; i < N + 1; i++) {
            F[i] = (F[i - 2] + F[i - 1]) % M;
        }

        System.out.println(F[N]);

    }

}
0