2700. Matrix Eqution

单点时限: 2.0 sec

内存限制: 256 MB

Once upon a time, Pellmen is so fond of solving math problems such as “find the smallest non-negative integer x which satisfy the expression A^x = B (mod C) where A,B,C are all given integer.”.

Now He wants to know if he could find the smallest x which satisfy the expression A^x = B(mod C),here both A and B are matrix whose size is n,and C are all given integers.

输入格式

There are no more than 20 cases;

There are 2 integers in the first line of each case which indicate n and C (1<=n<=20,1<=C<=2*10^9)

Then follow n lines indicate the matrix A,each line has exactly n integers.

Then another n lines indicate the matrix B, each line has exactly n integers.

All the numbers in the matrix are in the range [0,10^9];

**Note:Matrix A will not be an all-zero Matrix(before mod by C).

输出格式

a single line indicates the smallest x that you could find. If you could not find any x ,just print “No Solution!” in a single line.

you can assume that if there exist such x, the x is always smaller than 2^31

样例

Input
3 109
1 2 3
7 8 -34
12 -9841 2144
1 0 0
0 1 0
0 0 1
Output
0

1 人解决,5 人已尝试。

5 份提交通过,共有 22 份提交。

9.9 EMB 奖励。

创建: 14 年,9 月前.

修改: 6 年,10 月前.

最后提交: 11 年,2 月前.

来源: N/A

题目标签