function out = factorgroups( varargin )
%    disp("Number of input arguments: " + nargin)
%    celldisp(varargin)
    if nargin>1
      ngroups=varargin{2};
    else
      ngroups=3;
    end
    f=factor(varargin{1});
    nitems=length(f);
    maxn=ngroups^length(f);
    permlist=zeros(maxn,nitems);
    ourlist=zeros(maxn,ngroups);
    for n=1:maxn
	    for j=1:nitems

	    permlist(n,j)=mod(floor((n-1)/(ngroups^(j-1))),ngroups)+1;
    end
    end

    for n=1:maxn
       for j=1:ngroups
            outlist(n,j) = prod(f(find((permlist(n,:)==j))));
       end
    end
    out=unique(sort(outlist,2),'rows');
end
