69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
int n;
struct node {
int x[10][10];
};
void f(struct node a,struct node b){
struct node temp;
int i,j,m;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
temp.x[i][j]=0;
for(m=0;m<n;m++){
temp.x[i][j]+=(a.x[i][m]*b.x[m][j]);
temp.x[i][j]=temp.x[i][j]%9973;
}
}
}
for(i=0;i<n;i++){
for(j=0;j<n;j++)
a.x[i][j]=temp.x[i][j];
}
}
int main() {
int t,i,j,sum;
long long k;
struct node c,ans;
while(scanf("%d",&t)!=EOF){
while(t--){
scanf("%d %lld",&n,&k);
for(i=0;i<n;i++){
for(j=0;j<n;j++){
scanf("%d",&c.x[i][j]);
ans.x[i][j]=c.x[i][j];
}
}
k--;
while(k>0){
if(k%2==1){
f(ans,c);
}
k/=2;
f(c,c);
}
sum=0;
for(i=0;i<n;i++){
sum+=ans.x[i][i];
sum=sum%9973;
}
printf("%d\n",sum);
}
}
return 0;
}