题目分析
这道题跟我之前发的一道题几乎一样,这里我就不给出证明过程了,直接上代码。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MOD = 1024;
struct Matirx{
int r,c;
LL matirx[2][2];
};
Matirx one, start, another;
Matirx Mul(Matirx a, Matirx b){
Matirx c;
c.r = a.r;
c.c = b.c;
for(int i = 0; i < a.r; i++){
for(int j = 0; j < b.c; j++){
c.matirx[i][j] = 0;
for(int k = 0; k < a.c; k++)
c.matirx[i][j] = (c.matirx[i][j] + a.matirx[i][k]*b.matirx[k][j])%MOD;
}
}
return c;
}
Matirx Quick_pow(int n){
Matirx ret = one, temp = start;
while(n){
if(n&1) ret = Mul(ret, temp);
temp = Mul(temp, temp);
n >>= 1;
}
return ret;
}
void init(){
one.r = one.c = start.c = start.r = 2;
one.matirx[0][0] = 1;
one.matirx[0][1] = 0;
one.matirx[1][0] = 0;
one.matirx[1][1] = 1;
start.matirx[0][0] = 0;
start.matirx[0][1] = 1;
start.matirx[1][0] = -1;
start.matirx[1][1] = 10;
another.r = 2;
another.c = 1;
another.matirx[0][0] = 10;
another.matirx[1][0] = 98;
}
int main(){
int T,n;
scanf("%d", &T);
init();
while(T--){
scanf("%d", &n);
if(n == 1) printf("9\n");
else if(n == 2) printf("97\n");
else {
Matirx ret = Quick_pow(n-2);
Matirx ans = Mul(ret, another);
printf("%I64d\n", (ans.matirx[1][0]-1+MOD)%MOD);
}
}
return 0;
}