結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-28 23:33:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 231 ms / 2,000 ms
コード長 346 bytes
コンパイル時間 2,496 ms
コンパイル使用メモリ 72,552 KB
実行使用メモリ 58,260 KB
最終ジャッジ日時 2023-08-24 16:55:25
合計ジャッジ時間 5,115 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
56,260 KB
testcase_01 AC 121 ms
55,608 KB
testcase_02 AC 120 ms
55,400 KB
testcase_03 AC 121 ms
54,188 KB
testcase_04 AC 122 ms
55,644 KB
testcase_05 AC 121 ms
55,692 KB
testcase_06 AC 121 ms
56,428 KB
testcase_07 AC 120 ms
55,644 KB
testcase_08 AC 122 ms
55,836 KB
testcase_09 AC 130 ms
57,816 KB
testcase_10 AC 153 ms
58,260 KB
testcase_11 AC 228 ms
58,144 KB
testcase_12 AC 231 ms
55,716 KB
testcase_13 AC 224 ms
58,168 KB
testcase_14 AC 225 ms
58,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import static java.lang.System.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int m = sc.nextInt();
		Long A = 0L;
		Long B = 1L;
		Long C = A+B;
		for (int i=3; i<n; i++) {
			A = B;
			B = C;
			C = (A+B)%m;
		}
		out.println(C);
	}
}
0