Determinant of a matrix NxN with gcd