結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー htensaihtensai
提出日時 2019-12-19 12:34:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 573 bytes
コンパイル時間 4,200 ms
コンパイル使用メモリ 71,164 KB
実行使用メモリ 50,168 KB
最終ジャッジ日時 2023-09-21 06:41:54
合計ジャッジ時間 6,089 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,152 KB
testcase_01 AC 43 ms
49,344 KB
testcase_02 AC 44 ms
49,252 KB
testcase_03 AC 44 ms
49,036 KB
testcase_04 AC 44 ms
49,064 KB
testcase_05 AC 44 ms
49,156 KB
testcase_06 AC 44 ms
49,172 KB
testcase_07 AC 45 ms
49,028 KB
testcase_08 AC 45 ms
49,696 KB
testcase_09 AC 48 ms
49,308 KB
testcase_10 AC 66 ms
50,168 KB
testcase_11 AC 130 ms
50,088 KB
testcase_12 AC 130 ms
49,792 KB
testcase_13 AC 130 ms
49,792 KB
testcase_14 AC 130 ms
50,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] first = br.readLine().split(" ", 2);
        int n = Integer.parseInt(first[0]);
        int m = Integer.parseInt(first[1]);
        long prepre = 0;
        long pre = 1;
        for (int i = 3; i <= n; i++) {
            long now = (pre + prepre) % m;
            prepre = pre;
            pre = now;
        }
        System.out.println(pre);
    }
}
0