結果

問題 No.891 隣接3項間の漸化式
ユーザー tentententen
提出日時 2021-11-22 15:17:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 2,031 bytes
コンパイル時間 3,705 ms
コンパイル使用メモリ 74,316 KB
実行使用メモリ 49,952 KB
最終ジャッジ日時 2023-09-06 06:58:19
合計ジャッジ時間 7,758 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
49,360 KB
testcase_01 AC 42 ms
49,476 KB
testcase_02 AC 39 ms
49,464 KB
testcase_03 AC 40 ms
49,476 KB
testcase_04 AC 42 ms
49,480 KB
testcase_05 AC 41 ms
49,348 KB
testcase_06 AC 40 ms
49,476 KB
testcase_07 AC 40 ms
49,500 KB
testcase_08 AC 40 ms
49,360 KB
testcase_09 AC 39 ms
49,396 KB
testcase_10 AC 40 ms
49,436 KB
testcase_11 AC 40 ms
49,404 KB
testcase_12 AC 39 ms
49,756 KB
testcase_13 AC 41 ms
49,704 KB
testcase_14 AC 40 ms
49,328 KB
testcase_15 AC 41 ms
49,560 KB
testcase_16 AC 40 ms
49,420 KB
testcase_17 AC 41 ms
49,456 KB
testcase_18 AC 44 ms
49,564 KB
testcase_19 AC 42 ms
49,348 KB
testcase_20 AC 42 ms
49,460 KB
testcase_21 AC 42 ms
49,440 KB
testcase_22 AC 41 ms
49,468 KB
testcase_23 AC 42 ms
49,508 KB
testcase_24 AC 40 ms
49,952 KB
testcase_25 AC 39 ms
49,396 KB
testcase_26 AC 40 ms
49,408 KB
testcase_27 AC 40 ms
49,464 KB
testcase_28 AC 41 ms
49,396 KB
testcase_29 AC 42 ms
49,364 KB
testcase_30 AC 41 ms
49,360 KB
testcase_31 AC 40 ms
49,356 KB
testcase_32 AC 41 ms
49,796 KB
testcase_33 AC 41 ms
49,404 KB
testcase_34 AC 40 ms
49,900 KB
testcase_35 AC 40 ms
49,524 KB
testcase_36 AC 40 ms
49,496 KB
testcase_37 AC 40 ms
49,348 KB
testcase_38 AC 39 ms
47,920 KB
testcase_39 AC 40 ms
49,316 KB
testcase_40 AC 41 ms
49,476 KB
testcase_41 AC 41 ms
49,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int n = sc.nextInt();
        long[][][] matrixes = new long[30][2][2];
        matrixes[0][0][1] = 1;
        matrixes[0][1][0] = b;
        matrixes[0][1][1] = a;
        for (int i = 1; i < 30; i++) {
            for (int j = 0; j < 2; j++) {
                for (int k = 0; k < 2; k++) {
                    for (int l = 0; l < 2; l++) {
                        matrixes[i][j][l] += matrixes[i - 1][j][k] * matrixes[i - 1][k][l] % MOD;
                        matrixes[i][j][l] %= MOD;
                    }
                }
            }
        }
        long[] ans = new long[]{0, 1};
        for (int i = 29; i >= 0; i--) {
            if (n >= (1 << i)) {
                n -= (1 << i);
                long[] next = new long[2];
                for (int j = 0; j < 2; j++) {
                    for (int k = 0; k < 2; k++) {
                        next[j] += matrixes[i][j][k] * ans[k] % MOD;
                        next[j] %= MOD;
                    }
                }
                ans = next;
            }
        }
        System.out.println(ans[0]);
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0