結果
| 問題 |
No.3228 Very Large Fibonacci Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-08-08 22:55:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,642 bytes |
| コンパイル時間 | 1,880 ms |
| コンパイル使用メモリ | 204,440 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-08-08 22:55:17 |
| 合計ジャッジ時間 | 2,806 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const int N = 200005;
const int INF = 0x3f3f3f3f;
vector<vector<ll>> mul(vector<vector<ll>> mat1, vector<vector<ll>> mat2) {
vector<vector<ll>> res(4, vector<ll>(4, 0));
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
res[i][j] = (res[i][j] + mat1[i][k] * mat2[k][j]) % mod;
}
}
}
return res;
}
vector<vector<ll>> powmod(vector<vector<ll>> x, ll y) {
vector<vector<ll>> res(4, vector<ll>(4, 0));
for (int i = 0; i < 4; i++) res[i][i] = 1;
while (y) {
if (y & 1) res = mul(res, x);
y >>= 1;
x = mul(x, x);
}
return res;
}
int main() {
ll a, b, c, d, e, n;
cin >> a >> b >> c >> d >> e >> n;
if (n == 0) {
cout << (a % mod + mod) % mod << "\n";
return 0;
}
vector<vector<ll>> M(4, vector<ll>(4, 0));
M[0][0] = (c % mod + mod) % mod;
M[0][1] = (d % mod + mod) % mod;
M[0][2] = 1;
M[0][3] = 0;
M[1][0] = 1;
M[1][1] = 0;
M[1][2] = 0;
M[1][3] = 0;
M[2][0] = 0;
M[2][1] = 0;
M[2][2] = 1;
M[2][3] = 0;
M[3][0] = 1;
M[3][1] = 0;
M[3][2] = 0;
M[3][3] = 1;
vector<vector<ll>> P = powmod(M, n);
ll ans = 0;
ans = (ans + P[3][0] * (b % mod + mod) % mod) % mod;
ans = (ans + P[3][1] * (a % mod + mod) % mod) % mod;
ans = (ans + P[3][2] * (e % mod + mod) % mod) % mod;
ans = (ans + P[3][3] * (a % mod + mod) % mod) % mod;
cout << (ans % mod + mod) % mod << endl;
return 0;
}