8686: Matrix and GCD

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:2 通过:2

题目描述


Given an n×mn \times mn×m Matrix MMM where each integer iii (1≤i≤nm)(1 \le i \le nm)(1inm) appears exactly once in MMM. Let the value of a submatrix of MMM as the greatest common divisor (GCD) of all the entries among the submatrix, you need to determine the sum of the values for all continuous submatrices of MMM.


输入格式


The first line contains two integers nnn and mmm (1≤n,m≤1000)(1 \le n,m \le 1\,000)(1n,m1000).
Following nnn lines each contains mmm integers Mi,jM_{i,j}Mi,j (1≤Mi,j≤nm)(1\le M_{i,j} \le nm)(1Mi,jnm), denoting the given matrix.
It is guaranteed that each integer iii (1≤i≤nm)(1 \le i \le nm)(1inm) appears exactly once in MMM.

输出格式


Output one line containing one integer, denoting the answer.

输入样例 复制

3 3
1 2 3
4 5 6
7 8 9

输出样例 复制

78

分类标签