- #include <iostream>
- using namespace std;
- #define Error {cout<<"Error!"<<endl;return (*this);}
- class Mat
- {
- public:
- const static int MAX_MAT_SIZE=10;
- inline void init(int l,int c);
- inline Mat operator*(const Mat& b);
- inline void operator*=(const Mat& b);
- inline Mat operator+(const Mat& b);
- inline void operator+=(const Mat& b);
- inline Mat operator-(const Mat& b);
- inline void operator-=(const Mat& b);
- inline Mat operator^(int k);
- inline void show();
- void in(int l,int c);
- private:
- int mat[MAX_MAT_SIZE][MAX_MAT_SIZE];
- long long moudle;
- int size_l,size_c;
- };
- inline void Mat::init(int l,int c)
- {
- int i,j;
- for(i=0;i<l;i++)for(j=0;j<c;j++)mat[i][j]=0;
- size_l=l;size_c=c;
- moudle=10000;
- }
- inline Mat Mat::operator *(const Mat& b)
- {
- if(size_c!=b.size_l) Error
- int i,j,k;Mat tmp;
- tmp.init(size_l,b.size_c);
- for(i=0;i<size_l;i++)
- for(k=0;k<b.size_c;k++)
- for(j=0;j<size_c;j++)
- {tmp.mat[i][k]+=mat[i][j]*b.mat[j][k];if(tmp.mat[i][k]>=tmp.moudle)tmp.mat[i][k]%=tmp.moudle;}
- return tmp;
- }
- inline void Mat::operator *=(const Mat &b)
- {
- (*this)=(*this)*b;
- }
- inline Mat Mat::operator +(const Mat& b)
- {
- if(size_l!=b.size_l||size_c!=b.size_c) Error
- int i,j;Mat tmp;
- tmp.init(size_l,b.size_c);
- for(i=0;i<size_l;i++)
- for(j=0;j<size_c;j++)
- {tmp.mat[i][j]=mat[i][j]+b.mat[i][j];if(tmp.mat[i][j]>=tmp.moudle)tmp.mat[i][j]%=tmp.moudle;}
- return tmp;
- }
- inline void Mat::operator +=(const Mat& b)
- {
- (*this)=(*this)+b;
- }
- inline Mat Mat::operator -(const Mat& b)
- {
- if(size_l!=b.size_l||size_c!=b.size_c) Error
- int i,j;Mat tmp;
- tmp.init(size_l,b.size_c);
- for(i=0;i<size_l;i++)
- for(j=0;j<size_c;j++)
- tmp.mat[i][j]=mat[i][j]-b.mat[i][j];
- return tmp;
- }
- inline void Mat::operator -=(const Mat& b)
- {
- (*this)=(*this)-b;
- }
- inline Mat Mat::operator ^(int k)
- {
- if(k==1) return (*this);
- Mat tmp=(*this)*(*this);
- if(k&1) return (tmp^(k/2))*(*this);
- else return tmp^(k/2);
- }
- inline void Mat::show()
- {
- int i,j;
- for(i=0;i<size_l;cout<<mat[i++][j]<<endl)
- for(j=0;j<size_c-1;j++) cout<<mat[i][j]<<' ';
- }
- void Mat::in(int l,int c)
- {
- for(int i=0;i<l;i++)for(int j=0;j<c;j++)cin>>mat[i][j];
- }
- int main()
- {
- int l,c,k;
- Mat a,b;
- while(cin>>l>>c)
- {
- a.init(l,c);
- a.in(l,c);
- cin>>k;
- b=a^k;
- b.show();
- }
- return 0;
- }