結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー gu_21816943gu_21816943
提出日時 2017-06-26 01:24:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 241 ms / 2,000 ms
コード長 441 bytes
コンパイル時間 2,035 ms
コンパイル使用メモリ 74,860 KB
実行使用メモリ 54,284 KB
最終ジャッジ日時 2024-04-14 23:53:00
合計ジャッジ時間 5,158 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
54,264 KB
testcase_01 AC 129 ms
53,952 KB
testcase_02 AC 128 ms
54,172 KB
testcase_03 AC 129 ms
54,232 KB
testcase_04 AC 127 ms
53,984 KB
testcase_05 AC 128 ms
54,016 KB
testcase_06 AC 129 ms
54,236 KB
testcase_07 AC 130 ms
54,220 KB
testcase_08 AC 129 ms
54,072 KB
testcase_09 AC 131 ms
54,164 KB
testcase_10 AC 156 ms
54,284 KB
testcase_11 AC 241 ms
54,104 KB
testcase_12 AC 241 ms
54,132 KB
testcase_13 AC 238 ms
54,148 KB
testcase_14 AC 240 ms
54,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] str=sc.nextLine().split(" ");
		int[] num=new int[2];
		num[0]=Integer.parseInt(str[0]);
		num[1]=Integer.parseInt(str[1]);
		sc.close();
		long tmp1=0,tmp2=1;
		int count=2;
		while(count++<num[0]){
			long tmp=tmp1;
			tmp1=tmp2%num[1];
			tmp2=(tmp2+tmp)%num[1];
		}
		System.out.println(tmp2%num[1]);
	}
}
0