Tensor Product of Matrices
Time limit3sMemory limit128 MB
Count how many ways a given positive-integer matrix can be written as a tensor product A ⊗ B where neither factor is 1×1.
- Level
Medium7 of 10
- Topics
- Math, Number theory, Matrix, Brute force
- Solved
- No attempts yet
Problem
There is another way to multiply two matrices, called the tensor product (Kronecker product).
Let be a matrix and an matrix, where neither nor is a matrix.
The tensor product is a matrix obtained by replacing every entry of with the block .
For example:
Unlike ordinary matrix multiplication, there is no requirement that equal .
Given a matrix, write a program that counts the number of different ways it can be written as a tensor product , where and are matrices whose entries are positive integers and neither is a matrix. Two ways are considered different when the matrix or the matrix differs, either in size or in any entry.
Input
The input consists of several test cases.
The first line of each test case contains the matrix dimensions and . Each of the next lines contains the integers of one row of the matrix.
and are at most , and every entry of the matrix is an integer between and inclusive.
The last line of the input contains two zeros, marking the end of the input.
Output
For each test case, print on its own line the number of different ways the given matrix can be expressed as a tensor product .