結果

問題 No.793 うし数列 2
ユーザー YamaKasaYamaKasa
提出日時 2019-02-23 18:47:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 856 bytes
コンパイル時間 2,035 ms
コンパイル使用メモリ 75,260 KB
実行使用メモリ 39,764 KB
最終ジャッジ日時 2023-08-20 21:51:47
合計ジャッジ時間 6,034 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
39,204 KB
testcase_01 AC 125 ms
39,632 KB
testcase_02 AC 124 ms
39,164 KB
testcase_03 AC 127 ms
39,604 KB
testcase_04 AC 125 ms
39,384 KB
testcase_05 AC 127 ms
39,124 KB
testcase_06 AC 126 ms
39,100 KB
testcase_07 AC 126 ms
38,924 KB
testcase_08 AC 125 ms
39,128 KB
testcase_09 AC 124 ms
39,332 KB
testcase_10 AC 124 ms
39,516 KB
testcase_11 AC 125 ms
39,504 KB
testcase_12 AC 125 ms
39,396 KB
testcase_13 AC 127 ms
39,764 KB
testcase_14 AC 126 ms
39,276 KB
testcase_15 AC 126 ms
39,016 KB
testcase_16 AC 125 ms
39,016 KB
testcase_17 AC 122 ms
39,108 KB
testcase_18 AC 124 ms
39,092 KB
testcase_19 AC 123 ms
39,336 KB
testcase_20 AC 125 ms
39,044 KB
testcase_21 AC 125 ms
39,352 KB
testcase_22 AC 123 ms
39,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	static long mod = (long)(Math.pow(10, 9)) + 7;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		sc.close();
		long t = N - 1;
		long[][] A = {{10, 3}, {0, 1}};
		long[][] B = {{1, 0}, {0, 1}};
		while(t > 0) {
			if(t % 2 == 1) {
				B = mul(B, A);
			}
			t /= 2;
			A = mul(A, A);
			mod(A);
			mod(B);
		}
		long a = 13 * B[0][0] + B[0][1];
		System.out.println(a % mod);
	}
	static void mod(long[][] A){
		for(int i = 0; i < 2; i++) {
			for(int j = 0; j < 2; j++) {
				A[i][j] %= mod;
			}
		}
	}
	static long[][] mul(long[][] A, long[][] B){
		long[][] ret = new long[2][2];
		for(int i = 0; i < 2; i++) {
			for(int j = 0; j < 2; j++) {
				for(int k = 0; k < 2; k++) {
					ret[i][j] += A[i][k] * B[k][j];
				}
			}
		}
		return ret;
	}
}
0