結果
| 問題 | No.673 カブトムシ | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-04-21 19:57:24 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 141 ms / 2,000 ms | 
| コード長 | 1,326 bytes | 
| コンパイル時間 | 2,970 ms | 
| コンパイル使用メモリ | 78,520 KB | 
| 実行使用メモリ | 54,224 KB | 
| 最終ジャッジ日時 | 2024-06-30 06:11:07 | 
| 合計ジャッジ時間 | 6,085 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 14 | 
ソースコード
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);
		}
	}
}
            
            
            
        