Matrix and GCD
时间限制:C/C++/Rust/Pascal 4秒,其他语言8秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

Given an Matrix M where each integer i appears exactly once in M. Let the value of a submatrix of M 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 M.

输入描述:

The first line contains two integers n and m .
Following n lines each contains m integers , denoting the given matrix.
It is guaranteed that each integer i appears exactly once in M.

输出描述:

Output one line containing one integer, denoting the answer.
示例1

输入

复制
3 3
1 2 3
4 5 6
7 8 9

输出

复制
78