eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Here`s a Product Which Will Make You Tensor

Here`s a Product Which Will Make You Tensor

\includegraphics{https://static.e-olymp.com/content/da/da44184178d0ad691c101540e84480f04fe15be2.jpg} Most people are familiar with how to multiply two matrices together. However, an alternate form of multiplication known as tensor multiplication exists as well, and works more like you would expect matrix multiplication should. Let \textit{\textbf{A}} be a \textit{\textbf{p}}×\textit{\textbf{q}} matrix and \textit{\textbf{B}} be an \textit{\textbf{n}}×\textit{\textbf{m}} matrix, where neither \textit{\textbf{A}} nor \textit{\textbf{B}} is a \textbf{1}×\textbf{1} matrix. Then the tensor product \textbf{AB} is a \textit{\textbf{pn}}×\textit{\textbf{qm}} matrix formed by replacing each element \textit{\textbf{a_ij}} in \textbf{A} with the matrix (\textit{\textbf{a_ij}})·\textit{\textbf{B}}. Two examples are shown below, which also demonstrate that, like normal matrix multiplication, tensor multiplication is non-commutative: \includegraphics{https://static.e-olymp.com/content/32/3221988ffc3eb7fdfe5452903454f06602490310.jpg} Note that there is no restriction that the number of columns in the first matrix must equal the number of rows in the second, as there is with normal matrix multiplication. The object of this problem is to determine the number of ways (if any) a given matrix can be formed as a result of a tensor multiplication. \InputFile The first line of input for a test case will contain two positive integers \textit{\textbf{r}} and \textit{\textbf{c}} indicating the number of rows and columns in the matrix. After this will follow \textit{\textbf{r}} lines each containing \textit{\textbf{c}} positive integers. The values of \textit{\textbf{r}} and \textit{\textbf{c}} will be ≤ \textbf{500}, each entry in the matrix will be no greater than \textbf{65,536}, and the last test case is followed by a line containing \textbf{0 0}. \OutputFile For each test case, output the number of different ways the matrix could be the tensor product of two positive integer matrices, neither of which is a \textbf{1}×\textbf{1} matrix.
Лимит времени 4 секунды
Лимит использования памяти 32 MiB
Входные данные #1
6 6
1 1 1 2 2 2
1 1 1 2 2 2
1 1 2 2 2 4
3 3 3 4 4 4
3 3 3 4 4 4
3 3 6 4 4 8
2 2
3 6
4 9
2 4
15 18 30 36
20 24 40 48
0 0
Выходные данные #1
1
0
4