标签:
题目大意:
解题思路:再调用一下别人的图。。。
#include<cstdio>
#include<cstring>
using namespace std;
#define mod 1024
struct Matrix{
int mat[2][2];
}a, b, tmp;
int n;
void init() {
a.mat[0][0] = 5;
a.mat[0][1] = 12;
a.mat[1][0] = 2;
a.mat[1][1] = 5;
b.mat[0][0] = b.mat[1][1] = 1;
b.mat[0][1] = b.mat[1][0] = 0;
}
Matrix matrixMul(Matrix x, Matrix y) {
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++) {
tmp.mat[i][j] = 0;
for(int k = 0; k < 2; k++)
tmp.mat[i][j] += (x.mat[i][k] * y.mat[k][j]) % mod;
}
return tmp;
}
void solve() {
while(n) {
if(n & 1)
b = matrixMul(b,a);
a = matrixMul(a,a);
n >>= 1;
}
}
int main() {
int test;
scanf("%d", &test);
while(test--) {
scanf("%d", &n);
init();
solve();
printf("%d\n", (2 * b.mat[0][0] - 1 + mod) % mod);
}
return 0;
}
HDU - 2256 Problem of Precision 矩阵快速幂
标签:
原文地址:http://blog.csdn.net/l123012013048/article/details/45847097