結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー fkwnw3_1243fkwnw3_1243
提出日時 2017-09-08 23:12:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 677 bytes
コンパイル時間 3,364 ms
コンパイル使用メモリ 73,528 KB
実行使用メモリ 37,768 KB
最終ジャッジ日時 2024-04-24 21:08:37
合計ジャッジ時間 5,693 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
36,928 KB
testcase_01 AC 53 ms
36,984 KB
testcase_02 AC 53 ms
36,588 KB
testcase_03 AC 53 ms
36,640 KB
testcase_04 AC 53 ms
36,680 KB
testcase_05 AC 54 ms
36,832 KB
testcase_06 AC 53 ms
36,820 KB
testcase_07 AC 53 ms
37,128 KB
testcase_08 AC 53 ms
36,876 KB
testcase_09 AC 57 ms
36,568 KB
testcase_10 AC 78 ms
37,668 KB
testcase_11 AC 142 ms
37,700 KB
testcase_12 AC 142 ms
37,620 KB
testcase_13 AC 141 ms
37,652 KB
testcase_14 AC 140 ms
37,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.System.in;

public class No526 {
    public static void main(String[] args) throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String[] inputs = reader.readLine().split(" ");
        long N = Long.parseLong(inputs[0]);
        long M = Long.parseLong(inputs[1]);
        long fN_1 = 0;
        long fN_2 = 1;
        for (long i = 0; i < N - 2; i++) {
            long tmp = fN_2;
            fN_2 = (fN_1 + fN_2) % M;
            fN_1 = tmp;
        }

        System.out.println(fN_2 % M);

    }
}
0