結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー kazapyon27kazapyon27
提出日時 2017-06-11 20:09:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 641 bytes
コンパイル時間 3,711 ms
コンパイル使用メモリ 74,660 KB
実行使用メモリ 96,388 KB
最終ジャッジ日時 2023-10-24 21:15:46
合計ジャッジ時間 5,735 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
53,476 KB
testcase_01 AC 53 ms
53,476 KB
testcase_02 AC 53 ms
53,468 KB
testcase_03 AC 53 ms
53,476 KB
testcase_04 AC 54 ms
53,476 KB
testcase_05 AC 54 ms
53,476 KB
testcase_06 AC 54 ms
53,492 KB
testcase_07 AC 53 ms
53,480 KB
testcase_08 AC 56 ms
53,480 KB
testcase_09 AC 59 ms
53,476 KB
testcase_10 AC 86 ms
60,916 KB
testcase_11 AC 163 ms
94,952 KB
testcase_12 AC 158 ms
94,880 KB
testcase_13 AC 159 ms
94,872 KB
testcase_14 AC 161 ms
96,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*No.526 フィボナッチ数列の第N項をMで割った余りを求める*/
import java.io.*;
public class No526 {
	public static void main(String[] args) {
		try(BufferedReader input =new BufferedReader(new InputStreamReader(System.in))){
			String N_M[]=input.readLine().split(" ");
			long Ex_Fibo[]= new long[Integer.parseInt(N_M[0])];
			int devide=Integer.parseInt(N_M[1]);
			for(int i=0;i<Ex_Fibo.length;i++){
				if(i<=1){
					Ex_Fibo[i]=i%devide;
				}else{
					Ex_Fibo[i]=(Ex_Fibo[i-2]+Ex_Fibo[i-1])%devide;
				}
			}
			System.out.println(Ex_Fibo[Ex_Fibo.length-1]);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
0