結果

問題 No.3228 Very Large Fibonacci Sum
ユーザー Cafe1942
提出日時 2025-08-08 22:02:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,952 bytes
コンパイル時間 1,181 ms
コンパイル使用メモリ 123,180 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-08 22:02:08
合計ジャッジ時間 2,262 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>//小数点出力用
//cout << fixed << setprecision(10) << ans;
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
using ll = long long;
using namespace std;
#define modPHash (ll)((1LL<<61)-1)
#define modP (ll)1'000'000'007
bool chkrng0idx(int pos, int sup) { return (0 <= pos && pos < sup); }
int clk4(int num) { return (num - 2) * (num % 2); }
void yn(bool tf) { cout << (tf ? "Yes\n" : "No\n"); }

vector<vector<ll>> mul(vector<vector<ll>>& A, vector<vector<ll>>& B, int size) {
	vector<vector<ll>>res;
	for (int i = 0; i < size; i++) {
		vector<ll>row;
		for (int j = 0; j < size; j++) {
			ll tmp = 0;
			for (int k = 0; k < size; k++) {
				tmp += (A[i][k] * B[k][j]) % modP;
			}
			row.push_back(tmp % modP);
		}
		res.push_back(row);
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	vector<ll>I(4);
	vector<vector<ll>>M(4, I);
	ll X, Y, Z, ONE;
	ONE = 1;
	cin >> X;
	X += modP;
	X %= modP;
	Z = X;
	cin >> Y;
	Y += modP;
	Y %= modP;
	cin >> M[1][1] >> M[1][2] >> M[1][3];
	M[1][1] += modP;
	M[1][2] += modP;
	M[1][3] += modP;
	M[1][1] %= modP;
	M[1][2] %= modP;
	M[1][3] %= modP;
	ll N;
	cin >> N;
	M[0][0] = 1;
	M[0][1] = 1;
	M[2][1] = 1;
	M[3][3] = 1;
	vector<vector<ll>>EX[64];
	EX[0] = M;
	for (int k = 1;k < 64;k++) {
		EX[k] = mul(EX[k - 1], EX[k - 1], 4);
	}
	for (int k = 0;k < 64;k++) {
		if ((N >> k) & 1) {
			ll XX = (X * EX[k][0][0] + Y * EX[k][0][1] + Z * EX[k][0][2] + ONE * EX[k][0][3]) % modP;
			ll YY = (X * EX[k][1][0] + Y * EX[k][1][1] + Z * EX[k][1][2] + ONE * EX[k][1][3]) % modP;
			ll ZZ = (X * EX[k][2][0] + Y * EX[k][2][1] + Z * EX[k][2][2] + ONE * EX[k][2][3]) % modP;
			ll ONEONE = (X * EX[k][3][0] + Y * EX[k][3][1] + Z * EX[k][3][2] + ONE * EX[k][3][3]) % modP;
			X = XX;
			Y = YY;
			Z = ZZ;
			ONE = ONEONE;
		}
	}
	cout << X;
	return 0;
}

0