addhelp(first, "First n terms of the sequence, A027430.");
first(n) = {my(tuples = List(), res = vector(n));

forvec(x = vector(3, i, [1, n]), 
	listput(tuples, [x[1]*x[2]*x[3], x[3]])	
, 
	2
); 
listsort(tuples, 1);
if(tuples[1][1] != tuples[2][1], 
	res[tuples[1][2]]++
);

for(i = 2, #tuples, 
	if(tuples[i-1][1] != tuples[i][1],
		res[tuples[i][2]]++
	)
);

for(i = 2, n, 
	res[i] = res[i] + res[i-1]
); res
}