結果

問題 No.673 カブトムシ
ユーザー uafr_csuafr_cs
提出日時 2018-04-13 23:22:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 1,454 bytes
コンパイル時間 2,631 ms
コンパイル使用メモリ 73,568 KB
実行使用メモリ 56,300 KB
最終ジャッジ日時 2023-09-12 18:11:11
合計ジャッジ時間 5,231 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,928 KB
testcase_01 AC 123 ms
55,860 KB
testcase_02 AC 121 ms
55,868 KB
testcase_03 AC 122 ms
55,924 KB
testcase_04 AC 122 ms
55,800 KB
testcase_05 AC 123 ms
55,896 KB
testcase_06 AC 124 ms
55,664 KB
testcase_07 AC 124 ms
56,300 KB
testcase_08 AC 122 ms
55,996 KB
testcase_09 AC 124 ms
55,744 KB
testcase_10 AC 123 ms
55,640 KB
testcase_11 AC 120 ms
55,960 KB
testcase_12 AC 122 ms
55,624 KB
testcase_13 AC 124 ms
55,972 KB
testcase_14 AC 125 ms
55,600 KB
testcase_15 AC 123 ms
55,680 KB
testcase_16 AC 122 ms
55,888 KB
testcase_17 AC 123 ms
55,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	
	public static final long MOD = 1000000007;
	public static final int SIZE = 2;
	
	public static long[][] mat_pow(long[][] mat, long p){
		if(p == 0){
			return new long[][]{{1, 0}, {0, 1}};
		}else if(p == 1){
			return mat;
		}else if(p % 2 != 0){
			return mat_mul(mat, mat_pow(mat, p - 1));
		}else{
			final long[][] ret = mat_pow(mat, p / 2);
			return mat_mul(ret, ret);
		}
	}
	
	public static long[][] mat_mul(long[][] mat1, long[][] mat2){
		long[][] ret = new long[SIZE][SIZE];
		
		for(int i = 0; i < SIZE; i++){
			for(int j = 0; j < SIZE; j++){
				for(int k = 0; k < SIZE; k++){
					ret[i][j] += mat1[i][k] * mat2[k][j];
					ret[i][j] %= MOD;
				}
			}
		}
		
		return ret;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final long B = sc.nextLong();
		final long C = sc.nextLong();
		final long D = sc.nextLong();

		final long B_mod = B % MOD;
		final long C_mod = C % MOD;

		if(D == 1){
			System.out.println((B_mod * C_mod) % MOD);
			return;
		}
		
		
		final long[][] snd = mat_pow(new long[][]{{C_mod, 0}, {1, 1}}, D - 2);
		final long[][] fst = mat_mul(new long[][]{{C_mod, 0}, {(C_mod + 1) % MOD, 1}}, snd);
		//System.out.println(Arrays.deepToString(fst));
		
		final long X = (fst[1][0] * B_mod) % MOD;
		final long X_ = (X * C_mod) % MOD;
		System.out.println((X_) % MOD);
	}
}
0