We say a positive integer n is an perfect number if the sum of its all proper factors is exactly n. Now we have a matrix of R*C perfect numbers. If after swapping two neighboring numbers, there are at least three same number consecutively in a row/column, we say this move is “good”. How many “good” moves here?
First line contains an integer T (T<=100) indicating the number of test cases.
For each test case, first line contains two integer R, C (3<=R, C<=50) indicating the number of rows and columns respectively. Next R lines contains a sequence of C perfect numbers each. It is guaranteed that no three consecutive same numbers in a row/column initially.
For each test case, please output the number of “good” moves.
1 3 3 6 6 28 28 6 28 28 28 6
3
Migrated from old NTUJ.
tmt514
No. | Testdata Range | Score |
---|