結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー shinwisteriashinwisteria
提出日時 2018-03-13 20:20:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 346 bytes
コンパイル時間 3,569 ms
コンパイル使用メモリ 75,056 KB
実行使用メモリ 57,756 KB
最終ジャッジ日時 2023-08-15 09:20:45
合計ジャッジ時間 7,035 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
55,432 KB
testcase_01 AC 113 ms
55,652 KB
testcase_02 AC 112 ms
55,664 KB
testcase_03 AC 114 ms
55,616 KB
testcase_04 AC 114 ms
53,516 KB
testcase_05 AC 115 ms
54,672 KB
testcase_06 AC 114 ms
55,280 KB
testcase_07 AC 115 ms
55,300 KB
testcase_08 AC 113 ms
55,752 KB
testcase_09 AC 116 ms
55,780 KB
testcase_10 AC 128 ms
55,800 KB
testcase_11 AC 188 ms
55,652 KB
testcase_12 AC 189 ms
55,656 KB
testcase_13 AC 192 ms
57,756 KB
testcase_14 AC 192 ms
55,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package m.shin;
import java.util.Scanner;
public class Con526 {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		long m = s.nextLong();
		s.close();

		long a1 = 0,a2 = 1;
		for(int i = 3;i <= n;i++){
			long ai = (a1 + a2) % m;
			a1 = a2;
			a2 = ai;
		}
		System.out.println(a2);

	}

}
0