1 条题解
-
0DRAINF LV 8 MOD @ 2021-01-26 21:36:08
#include<bits/stdc++.h> using namespace std; class matrix{ long long a[4][4]; public: void start(){ a[1][1] = 0;a[1][2] = 1;a[1][3] = 0; a[2][1] = 1;a[2][2] = 1;a[2][3] = 0; a[3][1] = 0;a[3][2] = 1;a[3][3] = 1; } void pr(){ for (int i = 1; i <= 3;++i){ for (int j = 1; j <= 3;++j) cout << a[i][j] << ' '; cout << endl; } cout << endl; } long long x(){ return a[2][2]; } long long s(){ return a[3][2]; } matrix operator%(int mod){ matrix tmp; for (int i = 1; i <= 3;i++) for (int j = 1; j <= 3;j++) tmp.a[i][j] = (this->a[i][j]) % mod; return tmp; } matrix operator*(const matrix b){ matrix tmp; memset(tmp.a, 0, sizeof(tmp.a)); for (int i = 1; i <= 3;++i) for (int j = 1; j <= 3;++j) for (int k = 1; k <= 3;++k) tmp.a[i][j] += (this->a[i][k]) * b.a[k][j]; return tmp; } }; matrix qpow(matrix m,long long n){ if (n == 1) return m; if(n%2) return (qpow(m,n-1) * m)%114514; matrix tmp = qpow(m, n / 2)%114514; return (tmp * tmp)%114514; } int main(){ long long n; matrix m,ans; m.start(); cin >> n; if(n==0||n==1){ cout<<n<<" "<<n<<endl; return 0; } ans=qpow(m, n-1); cout << ans.x() << ' '; ans = ans * m%114514; cout << ans.s() << endl; return 0; }
- 1
信息
- ID
- 1001
- 难度
- 9
- 分类
- (无)
- 标签
- (无)
- 递交数
- 12
- 已通过
- 3
- 通过率
- 25%
- 被复制
- 1
- 上传者