結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー fal_rndfal_rnd
提出日時 2017-08-25 23:29:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 211 ms / 2,000 ms
コード長 570 bytes
コンパイル時間 1,999 ms
コンパイル使用メモリ 79,172 KB
実行使用メモリ 93,284 KB
最終ジャッジ日時 2024-04-23 15:46:33
合計ジャッジ時間 4,681 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
41,012 KB
testcase_01 AC 108 ms
40,108 KB
testcase_02 AC 101 ms
40,076 KB
testcase_03 AC 108 ms
41,188 KB
testcase_04 AC 107 ms
41,288 KB
testcase_05 AC 117 ms
41,336 KB
testcase_06 AC 99 ms
41,028 KB
testcase_07 AC 111 ms
40,812 KB
testcase_08 AC 119 ms
41,648 KB
testcase_09 AC 104 ms
41,864 KB
testcase_10 AC 136 ms
49,092 KB
testcase_11 AC 197 ms
82,304 KB
testcase_12 AC 211 ms
91,320 KB
testcase_13 AC 198 ms
93,284 KB
testcase_14 AC 210 ms
93,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static IntStream REPS(int v){return IntStream.range(0,v);}
	static IntStream REPS(int l,int r){return IntStream.rangeClosed(l,r);}
	static IntStream INS(int n) {return REPS(n).map(i->getInt());}
	static Scanner s=new Scanner(System.in);
	static int getInt(){return Integer.parseInt(s.next());}

	public static void main(String[]$){
		int n=getInt(),m=getInt();
		long[]r=new long[n];
		r[0]=0;
		r[1]=1;
		for(int i=2;i<n;++i)
			r[i]=(r[i-1]+r[i-2])%m;
		System.out.println(r[n-1]);
	}
}
0