結果

問題 No.1275 綺麗な式
ユーザー 57tggx57tggx
提出日時 2020-10-18 18:07:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 1,437 bytes
コンパイル時間 2,324 ms
コンパイル使用メモリ 74,292 KB
実行使用メモリ 56,072 KB
最終ジャッジ日時 2023-09-28 13:18:56
合計ジャッジ時間 12,379 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,836 KB
testcase_01 AC 124 ms
55,836 KB
testcase_02 AC 124 ms
55,772 KB
testcase_03 AC 120 ms
55,880 KB
testcase_04 AC 122 ms
55,440 KB
testcase_05 AC 122 ms
55,944 KB
testcase_06 AC 124 ms
55,692 KB
testcase_07 AC 124 ms
55,692 KB
testcase_08 AC 125 ms
55,648 KB
testcase_09 AC 125 ms
55,476 KB
testcase_10 AC 124 ms
55,660 KB
testcase_11 AC 123 ms
55,724 KB
testcase_12 AC 123 ms
55,836 KB
testcase_13 AC 122 ms
56,000 KB
testcase_14 AC 122 ms
53,372 KB
testcase_15 AC 121 ms
55,884 KB
testcase_16 AC 125 ms
55,716 KB
testcase_17 AC 122 ms
55,656 KB
testcase_18 AC 122 ms
55,788 KB
testcase_19 AC 121 ms
55,808 KB
testcase_20 AC 126 ms
55,696 KB
testcase_21 AC 121 ms
55,736 KB
testcase_22 AC 122 ms
55,428 KB
testcase_23 AC 122 ms
55,780 KB
testcase_24 AC 123 ms
55,476 KB
testcase_25 AC 121 ms
55,700 KB
testcase_26 AC 120 ms
53,672 KB
testcase_27 AC 120 ms
55,888 KB
testcase_28 AC 121 ms
55,848 KB
testcase_29 AC 123 ms
55,900 KB
testcase_30 AC 120 ms
55,980 KB
testcase_31 AC 124 ms
55,848 KB
testcase_32 AC 123 ms
56,016 KB
testcase_33 AC 125 ms
55,908 KB
testcase_34 AC 123 ms
55,564 KB
testcase_35 AC 125 ms
55,620 KB
testcase_36 AC 122 ms
56,072 KB
testcase_37 AC 121 ms
55,820 KB
testcase_38 AC 123 ms
55,840 KB
testcase_39 AC 124 ms
55,424 KB
testcase_40 AC 122 ms
55,740 KB
testcase_41 AC 123 ms
55,956 KB
testcase_42 AC 122 ms
55,808 KB
testcase_43 AC 121 ms
55,544 KB
testcase_44 AC 125 ms
55,696 KB
testcase_45 AC 125 ms
55,560 KB
testcase_46 AC 124 ms
55,716 KB
testcase_47 AC 125 ms
55,840 KB
testcase_48 AC 124 ms
55,760 KB
testcase_49 AC 121 ms
55,820 KB
testcase_50 AC 122 ms
55,696 KB
testcase_51 AC 125 ms
55,408 KB
testcase_52 AC 126 ms
55,624 KB
testcase_53 AC 124 ms
55,768 KB
testcase_54 AC 122 ms
55,672 KB
testcase_55 AC 125 ms
55,896 KB
testcase_56 AC 124 ms
55,996 KB
testcase_57 AC 124 ms
55,936 KB
testcase_58 AC 121 ms
55,692 KB
testcase_59 AC 122 ms
55,840 KB
testcase_60 AC 122 ms
55,952 KB
testcase_61 AC 122 ms
55,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

public class Main{
	public static void main(String[] args){
		java.util.Scanner sc = new java.util.Scanner(System.in);
		long a = Long.parseLong(sc.next());
		long b = Long.parseLong(sc.next());
		long n = Long.parseLong(sc.next());
		if(n == 0){
			System.out.println(2);
			return;
		}
		Matrix x = new Matrix(1, 0, 0, 1);
		long tmp = (b - a * a % 1000000007) % 1000000007;
		if(tmp < 0) tmp += 1000000007;
		Matrix y = new Matrix(a * 2 % 1000000007, tmp, 1, 0);
		--n;
		while(n != 0){
			if((n & 1) == 1){
				x.mul(y);
			}
			y.mul(y);
			n >>= 1;
		}

		// System.out.println(x.x00 + " " + x.x01);
		// System.out.println(x.x10 + " " + x.x11);
		System.out.println((x.x00 * a * 2 % 1000000007 + x.x01 * 2 % 1000000007) % 1000000007);
	}
}

class Matrix{
	long x00, x01, x10, x11;
	public Matrix(long x00, long x01, long x10, long x11){
		this.x00 = x00;
		this.x01 = x01;
		this.x10 = x10;
		this.x11 = x11;
	}
	public void mul(Matrix a){
		long tmp00 = x00;
		long tmp01 = x01;
		long tmp10 = x10;
		long tmp11 = x11;
		long a00 = a.x00;
		long a01 = a.x01;
		long a10 = a.x10;
		long a11 = a.x11;
		this.x00 = (tmp00 * a00 % 1000000007 + tmp01 * a10 % 1000000007) % 1000000007;
		this.x01 = (tmp00 * a01 % 1000000007 + tmp01 * a11 % 1000000007) % 1000000007;
		this.x10 = (tmp10 * a00 % 1000000007 + tmp11 * a10 % 1000000007) % 1000000007;
		this.x11 = (tmp10 * a01 % 1000000007 + tmp11 * a11 % 1000000007) % 1000000007;
	}
}

0