
function tab=factor_list(n)
 // n = prod( tab(:,1).^tab(:,2))
  f  = g_factor(n)
  l  = unique(f)
  p  = l
  nl = size(l, '*')
  for i=1:nl
    p(i) = sum(f==l(i));
  end
  tab=[l(:) p(:)];
  if n<>prod(tab(:,1).^tab(:,2))
    error('bug in factor_list')
  end
endfunction


function facs=g_factor(n, fac1)
  nrhs=argn(2)
  nn = n
  if nrhs<2, fac1=[], end
  if n<0
    fac=g_factor(-n)
    facs(1)=-facs(1)
  else
    i=2
    found=0
    while i<=sqrt(n) & ~found
      if modulo(n,i)==0
         n=n/i
         facs=[fac1 i g_factor(n)]
         found=1
      end
      i=i+1
    end
    if ~found
     facs=[fac1 n]
    end
    if nn<>prod(facs)
      error('bug in factor')
    end
  end
endfunction

