Let $A$ denote the first matrix in the product, and let $B$ denote the second.
I will consider only the case in which the entries of $B$ have one digit.
In this case, the "gluing" property of this matrix multiplication can be written as
$$
AB = 10A + B.
$$
Note that this equation can be rearranged into
$$
AB - 10 A - B + 10I = 10I \implies\\
(A - I)(B - 10 I)= 10 I,
$$
where $I$ denotes the identity matrix. Now, suppose that we select a matrix $B$ and we want a corresponding matrix $A$. We have
$$
(A - I)(B - 10 I) = 10 I \implies\\
A = 10(B - 10 I)^{-1} + I.
$$
Note that this equation only has a solution if $\det(B - 10 I) \neq 0$. Now, a question remains: how do we ensure that $10 (B - 10 I)^{-1}$ is an integer matrix? As it turns out, this will hold for a given integer matrix $B$ if and only if the determinant of $B - 10 I$ divides $10$.
In fact, we can generate pairs of matrices with non-negative integer entries that have the gluing property via the following steps:
- Find a matrix $C$ whose diagonal entries satisfy $-10 \leq c_{ii} \leq -1$ and whose off-diagonal entries are a single digit positive number such that the determinant of $C$ is either $-1$, $-2$, $-5$, or $-10$.
- Take $B = 10 I + C$ and $A = 10C^{-1} + I$.
For example, the matrix
$$
C = \pmatrix{-4 & 3\\7 &-4}
$$
has determinant $16 - 21 = -5$, which divides $10$. The corresponding matrix $B$ is
$$
B = 10 I + \pmatrix{-4 & 3\\7 &-4} = \pmatrix{6&3\\7&6}.
$$
The associated matrix $A$ is
$$
10C^{-1} + I = \frac{10}{-5} \cdot \pmatrix{-4 & -3\\-7 & -4} + \pmatrix{1&0\\0&1}
= \pmatrix{9 & 6\\14 & 9}.
$$
If we compute the product, we indeed find that
$$
\pmatrix{\color{blue}{9} & \color{blue}{6}\\
\color{blue}{14} & \color{blue}{9}} \cdot
\pmatrix{\color{green}{6} & \color{green}{3}\\
\color{green}{7} & \color{green}{6}} =
\pmatrix{\color{blue}{9}\color{green}{6} & \color{blue}{6}\color{green}{3}\\
\color{blue}{14}\color{green}{7} & \color{blue}{9}\color{green}{6}}.
$$
An interesting phenomenon: if $B$ is a single digit matrix for which there exists an $A,B$ pair with this "gluing" property, we will have $A = B$ if and only if $B$ is a "vampire matrix" (cf. my comment on the question), which holds if and only if $B$ has eigenvalues $0,11$, which holds if and only if $C = B - 10 I$ has eigenvalues $-10,1$, which holds if and only if $C$ has determinant $-10$ and trace $-9$.
Best Answer
Doing a $k\times l$ times $l\times m$ matrix multiplication in the straightforward way, every entry of the result is a scalar product of of two $l$-vectors, which requires $l$ multiplications and $l-1$ additions. Multiply that by the number $km$ of entries of the result (or don't multiply if you have sufficiently many processors to do everything in parallel).