結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
56,340 KB
testcase_01 AC 120 ms
57,524 KB
testcase_02 AC 119 ms
57,468 KB
testcase_03 AC 110 ms
56,300 KB
testcase_04 AC 121 ms
57,340 KB
testcase_05 AC 122 ms
57,456 KB
testcase_06 AC 121 ms
57,536 KB
testcase_07 AC 120 ms
57,428 KB
testcase_08 AC 120 ms
57,352 KB
testcase_09 AC 126 ms
57,660 KB
testcase_10 AC 142 ms
61,716 KB
testcase_11 WA -
testcase_12 AC 195 ms
78,996 KB
testcase_13 WA -
testcase_14 AC 184 ms
78,200 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();

        int F[] = new int[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