結果
問題 | No.718 行列のできるフィボナッチ数列道場 (1) |
ユーザー |
|
提出日時 | 2018-07-27 23:38:22 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 775 bytes |
コンパイル時間 | 1,638 ms |
コンパイル使用メモリ | 167,304 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 05:36:32 |
合計ジャッジ時間 | 2,205 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define mod 1000000007int main(){long long a[4][4] = {{1, 1, 1, 2}, {0, 1, 1, 2}, {0, 1, 0, 0}, {0, 1, 0, 1}};long long ans[4] = {1, 1, 0, 0};long long n; cin >> n; n--;while (n != 0) {if (n % 2) {long long tmp[4] = {0};for (int i = 0; i < 4; i++) {for (int j = 0; j < 4; j++) {tmp[i] += a[i][j] * ans[j];tmp[i] %= mod;}}swap(ans, tmp);}long long b[4][4] = {0};for (int i = 0; i < 4; i++) {for (int j = 0; j < 4; j++) {for (int k = 0; k < 4; k++) {b[i][j] += a[i][k] * a[k][j];b[i][j] %= mod;}}}swap(a, b);n /= 2;}cout << ans[0] << endl;return 0;}