标签:www img variant jpg acm tle inline cep ace
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1695 Accepted Submission(s): 1047
1 #include <bits/stdc++.h>
2 using namespace std;
3 const int mod = 1024;
4 typedef vector<int> vec;
5 typedef vector<vec> mat;
6
7 mat mul(mat &A, mat &B) {
8 mat C(A.size(), vec(B[0].size()));
9 for(int i = 0; i < A.size(); i ++) {
10 for(int j = 0; j < B[0].size(); j ++) {
11 for(int k = 0; k < B.size(); k ++) {
12 C[i][j] = (C[i][j] + A[i][k]*B[k][j]);
13 }
14 C[i][j] %= mod;
15 }
16 }
17 return C;
18 }
19
20 mat pow(mat A, int n) {
21 mat B(A.size(), vec(A[0].size()));
22 for(int i = 0; i < B.size(); i ++) B[i][i] = 1;
23 while(n) {
24 if(n&1) B = mul(A, B);
25 A = mul(A, A);
26 n >>= 1;
27 }
28 return B;
29 }
30
31 int main() {
32 int t, n;
33 cin >> t;
34 while(t--) {
35 cin >> n;
36 mat A(2, vec(2));
37 A[0][0] = 5; A[0][1] = 12;
38 A[1][0] = 2; A[1][1] = 5;
39 A = pow(A, n-1);
40 // cout << A[0][0]*5+A[0][1]*2 << ‘ ‘ << A[1][0]*5+A[1][1]*2 << endl;
41 int ans = (A[0][0]*5+A[0][1]*2)*2-1;
42 cout << ans%mod << endl;
43 }
44 return 0;
45 }
标签:www img variant jpg acm tle inline cep ace
原文地址:https://www.cnblogs.com/xingkongyihao/p/8994361.html