function factors = prime_factors ( n )

%*****************************************************************************80
%
%% prime_factors() returns the prime factors of an integer.
%
%  Discussion:
%
%    Repeated factors will be listed multiple times.
%    For instance, 75 = 3 * 5 * 5 so
%    factors = [ 3, 5, 5 ]
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    19 September 2024
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer n: a number whose prime factorization is desired.
%
%  Output:
%
%    integer factors{}: a list of the prime factors of n.
%
  if ( n ~= round ( n ) )
    error ( 'prime_factors(): Input n is not an integer!\n' );
  end

  if ( n < 1 )
    error ( 'prime_factors(): Input integer n is less than 1!\n' );
  end

  i = 2;
  factors = [];

  while ( i * i <= n )

    if ( mod ( n, i ) ~= 0 )
      i = i + 1;
    else
      n = n / i;
      factors = [ factors, i ];
    end
  end
%
%  This happens if n is prime.
%
  if ( 1 < n )
    factors = [ factors, n ];
  end

  return
end
