Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(){
- int tc,n;
- const long long mod = 1000000007;
- scanf("%d",&tc);
- for(int i=1;i<=tc;i++){
- scanf("%d",&n);
- long long temp[n][n];
- long long m[n][n];
- long long r[n][n];
- for(int j=0;j<n;j++){
- for(int k=0;k<n;k++){
- scanf("%lld",&m[j][k]);
- }
- }
- for(int b=0;b<n;b++){
- for(int d=0;d<n;d++){
- r[b][d]=m[b][d];
- }
- }
- for(int i=0;i<n-1;i++){
- long long sum = 0;
- for (int b=0;b<n;b++){
- for (int d=0;d<n;d++){
- for(int k=0;k<n;k++){
- sum += m[b][k]*r[k][d]%mod;
- }
- temp[b][d] = sum%mod;
- sum = 0;
- }
- }
- for (int b=0;b<n;b++){
- for (int d=0;d<n;d++){
- r[b][d] = temp[b][d];
- }
- }
- }
- printf("Case #%d:\n",i);
- for(int j=0;j<n;j++){
- for(int k=0;k<n;k++){
- if(k==n-1){
- printf("%lld\n",r[j][k]%mod);
- }else{
- printf("%lld ",r[j][k]%mod);
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement