結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
53,848 KB
testcase_01 AC 131 ms
53,992 KB
testcase_02 AC 129 ms
54,196 KB
testcase_03 AC 130 ms
54,148 KB
testcase_04 AC 128 ms
54,200 KB
testcase_05 AC 128 ms
53,920 KB
testcase_06 AC 126 ms
54,000 KB
testcase_07 AC 128 ms
53,924 KB
testcase_08 AC 130 ms
53,860 KB
testcase_09 AC 134 ms
54,172 KB
testcase_10 AC 149 ms
53,848 KB
testcase_11 WA -
testcase_12 AC 192 ms
54,088 KB
testcase_13 WA -
testcase_14 AC 194 ms
53,884 KB
権限があれば一括ダウンロードができます

ソースコード

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]);
		long fib1;
		if(n == 0){
			fib1=0%m;
		}
		else if(n == 1){
			fib1= 1%m;
		}
		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%m;
			n_1 = ans%m;
		}
		fib1= ans%m;
		}
		System.out.println(fib1);
		s.close();
	}

}
0