結果

問題 No.673 カブトムシ
ユーザー GrenacheGrenache
提出日時 2018-04-21 19:57:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 1,326 bytes
コンパイル時間 4,907 ms
コンパイル使用メモリ 75,076 KB
実行使用メモリ 56,392 KB
最終ジャッジ日時 2023-09-12 18:30:41
合計ジャッジ時間 7,489 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
56,168 KB
testcase_01 AC 123 ms
55,628 KB
testcase_02 AC 122 ms
55,912 KB
testcase_03 AC 121 ms
55,664 KB
testcase_04 AC 120 ms
55,676 KB
testcase_05 AC 122 ms
55,392 KB
testcase_06 AC 123 ms
54,240 KB
testcase_07 AC 124 ms
55,796 KB
testcase_08 AC 124 ms
55,916 KB
testcase_09 AC 120 ms
55,612 KB
testcase_10 AC 121 ms
55,744 KB
testcase_11 AC 120 ms
53,848 KB
testcase_12 AC 118 ms
55,632 KB
testcase_13 AC 120 ms
55,420 KB
testcase_14 AC 121 ms
55,672 KB
testcase_15 AC 122 ms
55,660 KB
testcase_16 AC 121 ms
56,392 KB
testcase_17 AC 120 ms
55,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


public class Main_yukicoder673 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		final int MOD = 1_000_000_007;

		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();

		pr.println(f(d, MOD, c % MOD, b % MOD));
    }

	private static long f(long n, int MOD, long c, long b) {
		long[] a = {c, c * b % MOD, 0, 1};
		long[] x = {0, 1};
		while(n > 0) {
			if (n % 2 != 0) {
				long tmp0 = (x[0] * a[0] + x[1] * a[1]) % MOD;
				long tmp1 = (x[0] * a[2] + x[1] * a[3]) % MOD;
				x[0] = tmp0;
				x[1] = tmp1;
			}
			long tmp0 = (a[0] * a[0] + a[1] * a[2]) % MOD;
			long tmp1 = a[1] * (a[0] + a[3]) % MOD;
			long tmp2 = a[2] * (a[0] + a[3]) % MOD;
			long tmp3 = (a[3] * a[3] + a[1] * a[2]) % MOD;
			a[0] = tmp0;
			a[1] = tmp1;
			a[2] = tmp2;
			a[3] = tmp3;
			n /= 2;
		}

		return x[0];
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);

		solve();

//		pr.close();
		pr.flush();
//		sc.close();
	}

	static String INPUT = null;

	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}
0