結果

問題 No.891 隣接3項間の漸化式
ユーザー tentententen
提出日時 2021-03-10 19:22:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 1,149 bytes
コンパイル時間 2,026 ms
コンパイル使用メモリ 77,188 KB
実行使用メモリ 37,284 KB
最終ジャッジ日時 2024-04-20 14:18:49
合計ジャッジ時間 4,862 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
37,284 KB
testcase_01 AC 44 ms
36,844 KB
testcase_02 AC 45 ms
36,692 KB
testcase_03 AC 45 ms
36,700 KB
testcase_04 AC 44 ms
36,988 KB
testcase_05 AC 46 ms
37,088 KB
testcase_06 AC 47 ms
36,520 KB
testcase_07 AC 44 ms
36,812 KB
testcase_08 AC 43 ms
37,064 KB
testcase_09 AC 45 ms
36,812 KB
testcase_10 AC 44 ms
36,700 KB
testcase_11 AC 47 ms
37,108 KB
testcase_12 AC 46 ms
37,116 KB
testcase_13 AC 44 ms
36,936 KB
testcase_14 AC 45 ms
37,088 KB
testcase_15 AC 45 ms
37,024 KB
testcase_16 AC 51 ms
36,872 KB
testcase_17 AC 46 ms
36,988 KB
testcase_18 AC 45 ms
36,948 KB
testcase_19 AC 47 ms
37,104 KB
testcase_20 AC 45 ms
36,792 KB
testcase_21 AC 44 ms
37,020 KB
testcase_22 AC 45 ms
37,236 KB
testcase_23 AC 44 ms
37,092 KB
testcase_24 AC 45 ms
36,784 KB
testcase_25 AC 44 ms
36,820 KB
testcase_26 AC 44 ms
36,784 KB
testcase_27 AC 45 ms
37,040 KB
testcase_28 AC 44 ms
37,084 KB
testcase_29 AC 44 ms
36,984 KB
testcase_30 AC 43 ms
37,168 KB
testcase_31 AC 46 ms
36,784 KB
testcase_32 AC 44 ms
37,220 KB
testcase_33 AC 45 ms
37,036 KB
testcase_34 AC 45 ms
36,864 KB
testcase_35 AC 44 ms
37,236 KB
testcase_36 AC 44 ms
37,020 KB
testcase_37 AC 45 ms
37,040 KB
testcase_38 AC 46 ms
36,568 KB
testcase_39 AC 46 ms
37,116 KB
testcase_40 AC 45 ms
36,872 KB
testcase_41 AC 45 ms
37,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] first = br.readLine().split(" ", 3);
		int a = Integer.parseInt(first[0]);
		int b = Integer.parseInt(first[1]);
		int n = Integer.parseInt(first[2]);
		long[][] xy = new long[31][4];
		xy[0] = new long[]{a, b, 1, 0};
		for (int i = 1; i < 31; i++) {
		    xy[i][0] = (xy[i - 1][0] * xy[i - 1][0] + xy[i - 1][1] * xy[i - 1][2]) % MOD;
		    xy[i][1] = (xy[i - 1][0] * xy[i - 1][1] + xy[i - 1][1] * xy[i - 1][3]) % MOD;
		    xy[i][2] = (xy[i - 1][2] * xy[i - 1][0] + xy[i - 1][3] * xy[i - 1][2]) % MOD;
		    xy[i][3] = (xy[i - 1][2] * xy[i - 1][1] + xy[i - 1][3] * xy[i - 1][3]) % MOD;
		}
		long x = 1;
		long y = 0;
		for (int i = 30; i >= 0 && n > 0; i--) {
		    if (n >= (1 << i)) {
		        n -= (1 << i);
		        long xx = (x * xy[i][0] + y * xy[i][1]) % MOD;
		        long yy = (x * xy[i][2] + y * xy[i][3]) % MOD;
		        x = xx;
		        y = yy;
		    }
		}
		System.out.println(y);
	}
}
0