s = 0
unseen = 1
seen(v) = bit test(s, v)
see(v) = s = bit or(s, 2^v); while (seen(unseen), unseen++)

other(p) = {
	my (m=if (p==1, 1, my (f=factor(p)); prime pi(f[#f~,1])));
	forstep (k=ceil(unseen/m)*m, oo, m,
		if (!seen(k),
			see(k);
			return (k);
		);
	);
}

v=1; for (n=1, 10 000, v=other(v); print (n " " v));

quit