結果
| 問題 |
No.891 隣接3項間の漸化式
|
| コンテスト | |
| ユーザー |
eve__fuyuki
|
| 提出日時 | 2024-04-24 21:20:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,098 bytes |
| コンパイル時間 | 2,368 ms |
| コンパイル使用メモリ | 205,080 KB |
| 最終ジャッジ日時 | 2025-02-21 08:49:30 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 39 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using mint = atcoder::modint1000000007;
void fast_io() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
}
using vec = vector<mint>;
using mat = vector<vec>;
mat mul(const mat& a, const mat& b) {
int n = a.size();
int m = b.size();
int k = b[0].size();
mat c(n, vec(k));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
for (int l = 0; l < k; l++) {
c[i][l] += a[i][j] * b[j][l];
}
}
}
return c;
}
mat pow(mat a, long long n) {
int m = a.size();
mat res(m, vec(m));
for (int i = 0; i < m; i++) {
res[i][i] = 1;
}
while (n > 0) {
if (n & 1) {
res = mul(res, a);
}
a = mul(a, a);
n >>= 1;
}
return res;
}
int main() {
fast_io();
int a, b, n;
cin >> a >> b >> n;
if (n == 0) {
cout << 0 << endl;
return 0;
}
mat A = {{a, b}, {1, 0}};
auto B = pow(A, n - 1);
cout << B[0][0].val() << '\n';
}
eve__fuyuki