結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー YamaKasaYamaKasa
提出日時 2018-06-02 19:25:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 231 ms / 2,000 ms
コード長 358 bytes
コンパイル時間 1,947 ms
コンパイル使用メモリ 71,476 KB
実行使用メモリ 97,928 KB
最終ジャッジ日時 2023-09-12 21:35:00
合計ジャッジ時間 5,152 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,676 KB
testcase_01 AC 123 ms
55,976 KB
testcase_02 AC 122 ms
55,776 KB
testcase_03 AC 122 ms
55,900 KB
testcase_04 AC 122 ms
56,044 KB
testcase_05 AC 121 ms
55,768 KB
testcase_06 AC 123 ms
55,920 KB
testcase_07 AC 122 ms
53,924 KB
testcase_08 AC 122 ms
55,864 KB
testcase_09 AC 127 ms
56,064 KB
testcase_10 AC 145 ms
62,256 KB
testcase_11 AC 229 ms
96,500 KB
testcase_12 AC 229 ms
96,768 KB
testcase_13 AC 231 ms
97,928 KB
testcase_14 AC 229 ms
96,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		long M = scan.nextLong();
		scan.close();
		long []F = new long[N];
		F[0] = 0;
		F[1] = 1;
		for(int i = 2; i < N; i++) {
			F[i] = (F[i - 1] + F[i - 2]) % M;
		}
		System.out.println(F[N - 1]);
	}
}
0