結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー takeya_okino
提出日時 2017-06-11 16:52:45
言語 Java
(openjdk 23)
結果
AC  
実行時間 252 ms / 2,000 ms
コード長 345 bytes
コンパイル時間 2,333 ms
コンパイル使用メモリ 74,244 KB
実行使用メモリ 96,340 KB
最終ジャッジ日時 2024-09-24 16:19:52
合計ジャッジ時間 5,070 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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