結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー tsunabittsunabit
提出日時 2019-06-14 21:57:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 392 bytes
コンパイル時間 3,240 ms
コンパイル使用メモリ 72,132 KB
実行使用メモリ 98,532 KB
最終ジャッジ日時 2023-08-09 00:26:40
合計ジャッジ時間 6,622 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
56,076 KB
testcase_01 AC 120 ms
56,408 KB
testcase_02 AC 123 ms
56,108 KB
testcase_03 AC 121 ms
56,212 KB
testcase_04 AC 122 ms
55,928 KB
testcase_05 AC 122 ms
55,748 KB
testcase_06 AC 122 ms
56,168 KB
testcase_07 AC 121 ms
55,900 KB
testcase_08 AC 121 ms
56,132 KB
testcase_09 AC 125 ms
55,892 KB
testcase_10 AC 148 ms
62,344 KB
testcase_11 AC 227 ms
98,216 KB
testcase_12 AC 226 ms
98,532 KB
testcase_13 AC 226 ms
97,820 KB
testcase_14 AC 222 ms
98,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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