結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー Grenache
提出日時 2017-06-17 07:17:33
言語 Java
(openjdk 23)
結果
AC  
実行時間 222 ms / 2,000 ms
コード長 686 bytes
コンパイル時間 6,432 ms
コンパイル使用メモリ 74,344 KB
実行使用メモリ 75,348 KB
最終ジャッジ日時 2024-10-01 09:12:37
合計ジャッジ時間 5,975 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

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


public class Main_yukicoder526 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();
		int m = sc.nextInt();

		int[] f = new int[n];
		f[0] = 0;
		f[1] = 1;

		for (int i = 2; i < n; i++) {
			f[i] = (int)(((long)f[i - 1] + f[i - 2]) % m);
		}

		pr.println(f[n - 1]);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0