結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
54,104 KB
testcase_01 WA -
testcase_02 AC 130 ms
53,884 KB
testcase_03 AC 128 ms
54,168 KB
testcase_04 WA -
testcase_05 AC 129 ms
54,060 KB
testcase_06 AC 129 ms
54,268 KB
testcase_07 WA -
testcase_08 AC 131 ms
54,212 KB
testcase_09 AC 135 ms
54,320 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 195 ms
53,976 KB
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]);
		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;
		}
		System.out.println(fib1);
		s.close();
	}

}
0