結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー syuki791syuki791
提出日時 2017-07-01 19:02:27
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 542 bytes
コンパイル時間 2,087 ms
コンパイル使用メモリ 74,620 KB
実行使用メモリ 54,528 KB
最終ジャッジ日時 2024-04-15 08:05:59
合計ジャッジ時間 4,805 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
54,244 KB
testcase_01 AC 130 ms
54,024 KB
testcase_02 AC 126 ms
54,180 KB
testcase_03 AC 125 ms
54,128 KB
testcase_04 AC 127 ms
53,884 KB
testcase_05 AC 128 ms
54,252 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	
	
	public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		
		String[] str = s.nextLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int m =Integer.parseInt(str[1]);
		int fib1;
		if(n == 0){
			fib1=0;
		}
		else if(n == 1){
			fib1= 1;
		}
		else{
		int n_1 = 1;
		int n_2 = 1;
		int ans = 0;
		
		for(int i = 3;i<n;i++){
			ans = n_1 + n_2;
			n_2 = n_1;
			n_1 = ans;
		}
		fib1= ans;
		}
		long ans = fib1 % m;
		System.out.println(ans);
		s.close();
	}

}
0