結果

問題 No.718 行列のできるフィボナッチ数列道場 (1)
ユーザー PachicobuePachicobue
提出日時 2018-07-28 03:49:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 965 bytes
コンパイル時間 2,006 ms
コンパイル使用メモリ 198,344 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-19 05:55:00
合計ジャッジ時間 3,225 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//=================================
// Created on: 2018/07/28 03:44:33
//=================================
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << x << std::endl
using ll = long long;
using V = std::array<ll, 2>;
using M = std::array<V, 2>;
constexpr ll MOD = 1e9 + 7;
M mul(const M& m1, const M& m2)
{
    M ans{{{0, 0}, {0, 0}}};
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) { (ans[i][j] += m1[i][k] * m2[k][j]) %= MOD; }
        }
    }
    return ans;
}
M pow(const M& m, const ll n)
{
    if (n == 0) { return M{{{1, 0}, {0, 1}}}; }
    if (n % 2 == 1) {
        return mul(pow(m, n - 1), m);
    } else {
        const auto pp = pow(m, n / 2);
        return mul(pp, pp);
    }
}
int main()
{
    ll N;
    std::cin >> N;
    const M m{{{1, 1}, {1, 0}}}, mm = pow(m, N), mmm = mul(mm, m);
    std::cout << mm[0][1] * mmm[0][1] % MOD << std::endl;
    return 0;
}
0