2 条题解
-
1
#include<bits/stdc++.h> #define int long long using namespace std; const int mod = 1000000007; struct Matrix { int a[3][3]; Matrix() { memset(a, 0, sizeof a); } Matrix operator*(const Matrix &b) const { Matrix res; for (int i = 1; i <= 2; ++i) for (int j = 1; j <= 2; ++j) for (int k = 1; k <= 2; ++k) res.a[i][j] = (res.a[i][j] + a[i][k] * b.a[k][j]) % mod; return res; } } ans, base; void init() { base.a[1][1] = base.a[1][2] = base.a[2][1] = 1; ans.a[1][1] = ans.a[1][2] = 1; } void qpow(int b) { while (b) { if (b & 1) ans = ans * base; base = base * base; b >>= 1; } } signed main() { int n; cin>>n; if (n <= 2) return puts("1"), 0; init(); qpow(n - 2); cout<<ans.a[1][1] % mod; return 0; }
信息
- ID
- 116
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 8
- 标签
- 递交数
- 75
- 已通过
- 10
- 上传者