2014
11-05

# An easy Problem

We define eA as following:
Where A is a n×n symmetric matrix with real elements, I is an identity matrix.

There are several test cases;
Each test case begin with a line contains an integer n (1≤n≤100), the following n lines contain n×n symmetric matrix A. The rang of elements of A is (-100,100);
n=0 is the end of input and need not to proceed.

There are several test cases;
Each test case begin with a line contains an integer n (1≤n≤100), the following n lines contain n×n symmetric matrix A. The rang of elements of A is (-100,100);
n=0 is the end of input and need not to proceed.

1
2
2
1 0
0 1
0

7.39
2.72 0.00
0.00 2.72

#include<stdio.h>
int n;
struct Matrix
{
double arr[101][101];
};
Matrix mul(Matrix A, Matrix B)
{
Matrix res;
int i,j,k;
double s;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
s=0.0;
for(k=0;k<n;k++)
{
s+=A.arr[i][k]*B.arr[k][j];
}
res.arr[i][j]=s;
}
return res;
}
{
Matrix res;
int i,j;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
res.arr[i][j]=A.arr[i][j]+B.arr[i][j];
return res;
}
Matrix chufa(Matrix A, int k)
{
Matrix res;
int i,j;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
res.arr[i][j]=A.arr[i][j]/k;
return res;
}
bool ok(Matrix A)
{
int i,j;
bool flag=1;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(A.arr[i][j] > 0.001) flag=0;
}
return flag;
}
int main()
{
int i,j;
while(scanf("%d",&n) && n)
{
Matrix A, I, res;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
scanf("%lf",&A.arr[i][j]);
res.arr[i][j]=A.arr[i][j];
I.arr[i][j] = (i==j)?1.0:0;
}
int k=2;
while(k<=50)
{
res=chufa(res,k);
res=mul(res,A);
k++;
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%.2f ",I.arr[i][j]);
}
printf("\n");
}
}
}

1. 为什么for循环找到的i一定是素数叻，而且约数定理说的是n=p1^a1*p2^a2*p3^a3*…*pk^ak，而你每次取余都用的是原来的m，也就是n