/*
Copyright 2011 Marek "p2004a" Rusinowski
Matrix multiplication (simplest way)
*/
#include <cstdio>
#include <cstring>
const int cmod = 1000000007 ;
int n;
int * multiply( int * l, int * r) {
int * res = new int [ n * n] ;
for ( int i = 0 ; i < n; ++ i) {
for ( int k = 0 ; k < n; ++ k) {
for ( int j = 0 ; j < n; ++ j) {
* ( res + n * i + j) + = * ( l + n * i + k) * * ( r + n * k + j) % cmod;
* ( res + n * i + j) % = cmod;
}
}
}
return res;
}
void read_matrix( int * t) {
for ( int i = 0 ; i < n; ++ i) {
for ( int j = 0 ; j < n; ++ j) {
scanf ( "%d" , t + n * i + j) ;
}
}
}
int main( ) {
scanf ( "%d" , & n) ;
int * a = new int [ n * n] , * b = new int [ n * n] ;
read_matrix( a) ;
read_matrix( b) ;
int * res = multiply( a, b) ;
for ( int i = 0 ; i < n; ++ i) {
for ( int j = 0 ; j < n; ++ j) {
printf ( "%3d " , * ( res + n * i + j) ) ;
}
printf ( "\n " ) ;
}
delete a;
delete b;
return 0 ;
}
LyoKICBDb3B5cmlnaHQgMjAxMSBNYXJlayAicDIwMDRhIiBSdXNpbm93c2tpCiAgTWF0cml4IG11bHRpcGxpY2F0aW9uIChzaW1wbGVzdCB3YXkpCiovCiNpbmNsdWRlIDxjc3RkaW8+CiNpbmNsdWRlIDxjc3RyaW5nPgoKY29uc3QgaW50IGNtb2QgPSAxMDAwMDAwMDA3OwppbnQgbjsKCmludCAqbXVsdGlwbHkoaW50ICpsLCBpbnQgKnIpIHsKICBpbnQgKnJlcyA9IG5ldyBpbnQgW24gKiBuXTsKICBmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkgewogICAgZm9yIChpbnQgayA9IDA7IGsgPCBuOyArK2spIHsKICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBuOyArK2opIHsKICAgICAgICAqKHJlcyArIG4gKiBpICsgaikgKz0gKihsICsgbiAqIGkgKyBrKSAqICoociArIG4gKiBrICsgaikgJSBjbW9kOwogICAgICAgICoocmVzICsgbiAqIGkgKyBqKSAlPSBjbW9kOwogICAgICB9CiAgICB9CiAgfQogIHJldHVybiByZXM7Cn0KCnZvaWQgcmVhZF9tYXRyaXgoaW50ICp0KSB7CiAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArK2kpIHsKICAgIGZvciAoaW50IGogPSAwOyBqIDwgbjsgKytqKSB7CiAgICAgIHNjYW5mKCIlZCIsIHQgKyBuICogaSArIGopOwogICAgfQogIH0KfQoKaW50IG1haW4oKSB7CiAgc2NhbmYoIiVkIiwgJm4pOwogIGludCAqYSA9IG5ldyBpbnQgW24gKiBuXSwgKmIgPSBuZXcgaW50IFtuICogbl07CiAgcmVhZF9tYXRyaXgoYSk7CiAgcmVhZF9tYXRyaXgoYik7CiAgaW50ICpyZXMgPSBtdWx0aXBseShhLCBiKTsKICBmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkgewogICAgZm9yIChpbnQgaiA9IDA7IGogPCBuOyArK2opIHsKICAgICAgcHJpbnRmKCIlM2QgIiwgKihyZXMgKyBuICogaSArIGopKTsKICAgIH0KICAgIHByaW50ZigiXG4iKTsKICB9CiAgZGVsZXRlIGE7CiAgZGVsZXRlIGI7CiAgcmV0dXJuIDA7Cn0K
compilation info
prog.cpp: In function ‘void read_matrix(int*)’:
prog.cpp:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
prog.cpp: In function ‘int main()’:
prog.cpp:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
stdout