結果

問題 No.3006 ベイカーの問題
ユーザー eve__fuyuki
提出日時 2025-01-24 20:18:40
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,809 bytes
コンパイル時間 2,632 ms
コンパイル使用メモリ 207,608 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-01-24 20:18:44
合計ジャッジ時間 4,079 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

void fast_io() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
}
#include <atcoder/modint>
using mint = atcoder::modint998244353;
using vec = vector<mint>;
using mat = vector<vec>;
mat operator+(const mat &a, const mat &b) {
	int n = a.size();
	int m = a[0].size();
	mat c(n, vec(m));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			c[i][j] = a[i][j] + b[i][j];
		}
	}
	return c;
}
mat operator-(const mat &a, const mat &b) {
	int n = a.size();
	int m = a[0].size();
	mat c(n, vec(m));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			c[i][j] = a[i][j] - b[i][j];
		}
	}
	return c;
}
mat mul(mat a, mat b) {
	int n = a.size();
	int m = b.size();
	int l = b[0].size();
	mat c(n, vec(l));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			for (int k = 0; k < l; k++) {
				c[i][k] += a[i][j] * b[j][k];
			}
		}
	}
	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;
}
mat inv(mat a) {
	assert(a.size() == 2);
	mint det = a[0][0] * a[1][1] - a[0][1] * a[1][0];
	mat b = {{a[1][1], -a[0][1]}, {-a[1][0], a[0][0]}};
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			b[i][j] /= det;
		}
	}
	return b;
}
int main() {
	fast_io();
	long long x1, y1, n;
	cin >> x1 >> y1 >> n;
	mint x = x1, y = y1;
	if (x == 1 && y == 0) {
		cout << mint(n).val() << " " << 0 << endl;
		return 0;
	}
	mat A = {{x, -5 * y}, {y, x}};
	// A * (A^n - I) / (A - I)
	mat B = pow(A, n) - mat{{1, 0}, {0, 1}};
	mat C = inv(A - mat{{1, 0}, {0, 1}});
	mat b = mul(A, mul(C, B));

	cout << b[0][0].val() << " " << b[1][0].val() << endl;
}
0