結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー htensaihtensai
提出日時 2019-11-16 13:07:03
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 387 bytes
コンパイル時間 2,979 ms
コンパイル使用メモリ 74,684 KB
実行使用メモリ 57,736 KB
最終ジャッジ日時 2023-10-25 03:51:00
合計ジャッジ時間 5,218 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
57,268 KB
testcase_01 AC 132 ms
57,392 KB
testcase_02 AC 133 ms
57,436 KB
testcase_03 AC 130 ms
57,360 KB
testcase_04 AC 133 ms
57,636 KB
testcase_05 AC 132 ms
57,392 KB
testcase_06 AC 135 ms
57,356 KB
testcase_07 AC 135 ms
57,392 KB
testcase_08 AC 132 ms
55,148 KB
testcase_09 AC 138 ms
57,096 KB
testcase_10 AC 150 ms
57,524 KB
testcase_11 WA -
testcase_12 AC 196 ms
57,372 KB
testcase_13 WA -
testcase_14 AC 193 ms
57,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int preprev = 0;
		int prev = 1;
		for (int i = 3; i <= n; i++) {
		    int value = preprev + prev;
		    value %= m;
		    preprev = prev;
		    prev = value;
		}
		System.out.println(prev);
	}
}
0