結果

問題 No.718 行列のできるフィボナッチ数列道場 (1)
ユーザー tentententen
提出日時 2021-01-28 11:24:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 1,224 bytes
コンパイル時間 3,009 ms
コンパイル使用メモリ 73,984 KB
実行使用メモリ 56,492 KB
最終ジャッジ日時 2023-09-08 02:34:26
合計ジャッジ時間 6,628 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,924 KB
testcase_01 AC 120 ms
56,252 KB
testcase_02 AC 120 ms
55,728 KB
testcase_03 AC 119 ms
56,188 KB
testcase_04 AC 119 ms
55,948 KB
testcase_05 AC 119 ms
56,024 KB
testcase_06 AC 118 ms
56,000 KB
testcase_07 AC 115 ms
56,184 KB
testcase_08 AC 117 ms
56,228 KB
testcase_09 AC 117 ms
56,068 KB
testcase_10 AC 116 ms
55,748 KB
testcase_11 AC 116 ms
56,396 KB
testcase_12 AC 121 ms
56,492 KB
testcase_13 AC 118 ms
56,328 KB
testcase_14 AC 113 ms
56,136 KB
testcase_15 AC 118 ms
56,132 KB
testcase_16 AC 116 ms
56,228 KB
testcase_17 AC 117 ms
56,004 KB
testcase_18 AC 118 ms
56,284 KB
testcase_19 AC 121 ms
56,256 KB
testcase_20 AC 121 ms
55,832 KB
testcase_21 AC 120 ms
56,016 KB
testcase_22 AC 125 ms
53,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long[][] xy = new long[35][4];
        xy[0] = new long[]{1L, 1L, 1L, 0};
        for (int i = 1; i < 35; i++) {
            xy[i][0] = (xy[i - 1][0] * xy[i - 1][0] % MOD + xy[i - 1][1] * xy[i - 1][2] % MOD) % MOD;
            xy[i][1] = (xy[i - 1][0] * xy[i - 1][1] % MOD + xy[i - 1][1] * xy[i - 1][3] % MOD) % MOD;
            xy[i][2] = (xy[i - 1][2] * xy[i - 1][0] % MOD + xy[i - 1][3] * xy[i - 1][2] % MOD) % MOD;
            xy[i][3] = (xy[i - 1][2] * xy[i - 1][1] % MOD + xy[i - 1][3] * xy[i - 1][3] % MOD) % MOD;
        }
        long[] base = new long[]{1, 0};
        for (int i = 34; i >= 0 && n > 0; i--) {
            if (n >= (1L << i)) {
                n -= 1L << i;
                long next0 = (base[0] * xy[i][0] % MOD + base[1] * xy[i][2] % MOD) % MOD;
                long next1 = (base[0] * xy[i][1] % MOD + base[1] * xy[i][3] % MOD) % MOD;
                base[0] = next0;
                base[1] = next1;
            }
        }
        System.out.println(base[0] * base[1] % MOD);
    }
}
0