結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー YamaKasa
提出日時 2018-06-02 19:25:59
言語 Java
(openjdk 23)
結果
AC  
実行時間 235 ms / 2,000 ms
コード長 358 bytes
コンパイル時間 3,076 ms
コンパイル使用メモリ 75,744 KB
実行使用メモリ 81,980 KB
最終ジャッジ日時 2024-06-30 09:04:50
合計ジャッジ時間 5,091 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

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