結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー mosmos_21mosmos_21
提出日時 2017-06-10 20:44:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 223 ms / 2,000 ms
コード長 337 bytes
コンパイル時間 2,270 ms
コンパイル使用メモリ 74,064 KB
実行使用メモリ 99,300 KB
最終ジャッジ日時 2023-10-24 20:35:13
合計ジャッジ時間 4,882 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
57,256 KB
testcase_01 AC 114 ms
56,300 KB
testcase_02 AC 122 ms
57,396 KB
testcase_03 AC 125 ms
57,424 KB
testcase_04 AC 120 ms
57,588 KB
testcase_05 AC 122 ms
57,352 KB
testcase_06 AC 119 ms
57,176 KB
testcase_07 AC 111 ms
56,220 KB
testcase_08 AC 122 ms
57,648 KB
testcase_09 AC 122 ms
57,404 KB
testcase_10 AC 145 ms
63,680 KB
testcase_11 AC 222 ms
99,300 KB
testcase_12 AC 213 ms
98,720 KB
testcase_13 AC 217 ms
98,596 KB
testcase_14 AC 223 ms
99,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	static Scanner in = new Scanner(System.in);
	public static void main(String[] args){
		int n = in.nextInt(), m = in.nextInt();
		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