1 条题解
-
0
#include <bits/stdc++.h> using namespace std; long long mod ; struct Mat{ long long a11 = 0, a12 = 0, a21 = 0, a22 = 0; Mat operator*(const Mat &b) const{ Mat res; res.a11 = (a11 * b.a11 + a12 * b.a21)%mod; res.a12 = (a11 * b.a12 + a12 * b.a22)%mod; res.a21 = (a21 * b.a11 + a22 * b.a21)%mod; res.a22 = (a21 * b.a12 + a22 * b.a22)%mod; return res; } }; Mat matrix_pow(Mat a, long long b){ Mat res; res.a11 = 1; res.a22 = 1; while(b){ if(b & 1){ res = res * a; } a = a * a; b >>= 1; } return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n >> mod; Mat a; a.a11 = 1; a.a12 = 1; a.a21 = 1; a.a22 = 0; Mat b = matrix_pow(a,n-1); cout << b.a11; return 0; }
信息
- ID
- 1778
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 6
- 标签
- 递交数
- 23
- 已通过
- 11
- 上传者