function A = smith_matrix ( n )

%*****************************************************************************80
%
%% smith_matrix() returns the SMITH matrix.
%
%  Formula:
%
%    A(i,j) = gcd(i,j)
%
%    A =
%     1     1     1     1     1     1     1     1
%     1     2     1     2     1     2     1     2
%     1     1     3     1     1     3     1     1
%     1     2     1     4     1     2     1     4
%     1     1     1     1     5     1     1     1
%     1     2     3     2     1     6     1     2
%     1     1     1     1     1     1     7     1
%     1     2     1     4     1     2     1     8
%
%  Properties:
%
%    det(A) = phi(1) * phi(2) * ... * phi(n)
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    30 June 2022
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    John D Cook,
%    Smith's Determinant,
%    https://www.johndcook.com/blog/2013/07/31/smiths-determinant/
%    Posted 31 July 2013.
%
%    Donald Knuth,
%    The Art of Computer Programming,
%    Volume 2, Seminumerical Algorithms,
%    Section 4.5.2, problem 42.
%    Third Edition,
%    Addison Wesley, 1997,
%    ISBN: 0201896842,
%    LC: QA76.6.K64.
%
%  Input:
%
%    integer N: the order of the matrix.
%
%  Output:
%
%    real A(N,N), the matrix.
%
  A = zeros ( n, n );
  for i = 1 : n
    for j = 1 : n
      A(i,j) = gcd ( i, j );
    end
  end

  return
end
