結果

問題 No.673 カブトムシ
コンテスト
ユーザー zelda_master
提出日時 2026-11-22 16:40:20
言語 C++14
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 818µs
コード長 1,161 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 383 ms
コンパイル使用メモリ 80,588 KB
実行使用メモリ 9,876 KB
最終ジャッジ日時 2026-11-22 16:40:22
合計ジャッジ時間 2,529 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <cstdio>

using namespace std;

typedef long long LL;

const int MOD = 1000000007;

LL b, c, d;

struct Matrix {
    LL v[3][3];
    Matrix operator *(Matrix o) {
        Matrix ret = {};
        for (int i = 1; i <= 2; ++i) {
            for (int j = 1; j <= 2; ++j) {
                for (int k = 1; k <= 2; ++k) {
                    ret.v[i][k] = (ret.v[i][k] + v[i][j] * o.v[j][k] % MOD) % MOD;
                }
            }
        }
        return ret;
    }
    Matrix operator *=(Matrix o) {
        *this = *this * o;
        return *this;
    }
};
Matrix A;

Matrix QMI(Matrix a, LL k) {
    Matrix ret = {};
    ret.v[1][1] = ret.v[2][2] = 1;
    while (k) {
        if (k & 1) ret *= a;
        a *= a;
        k >>= 1;
    }
    return ret;
}

int main() {
    scanf("%lld%lld%lld", &b, &c, &d);

    b %= MOD, c %= MOD;

    A.v[1][1] = b % MOD * c % MOD;
    A.v[1][2] = b % MOD;
    A.v[2][1] = 0;
    A.v[2][2] = b % MOD;

    Matrix B = {};
    B.v[1][1] = c % MOD;
    B.v[1][2] = 0;
    B.v[2][1] = c % MOD;
    B.v[2][2] = 1;

    A *= QMI(B, d - 1);

    printf("%lld\n", A.v[1][1] % MOD);

    return 0;
}
0