結果
| 問題 |
No.2156 ぞい文字列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-12-09 22:27:38 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 845 bytes |
| コンパイル時間 | 4,349 ms |
| コンパイル使用メモリ | 249,696 KB |
| 最終ジャッジ日時 | 2025-02-09 08:28:46 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
#include <atcoder/all>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
using namespace atcoder;
using namespace std;
using mint = modint998244353;
struct Matrix {
mint mat[2][2];
};
Matrix mul(Matrix a, Matrix b) {
Matrix c;
rep(i, 2) rep(j, 2) {
c.mat[i][j] = 0;
rep(k, 2) c.mat[i][j] += a.mat[i][k] * b.mat[k][j];
}
return c;
}
Matrix pow(Matrix a, ll n) {
if (n == 1) return a;
Matrix res;
if (n % 2 == 0) {
res = pow(a, n / 2);
return mul(res, res);
} else {
res = pow(a, n - 1);
return mul(res, a);
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
ll N;
cin >> N;
Matrix A = {{{1, 1}, {1, 0}}};
Matrix B = pow(A, N);
cout << (B.mat[0][0] - 1).val() << "\n";
return 0;
}