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, prime pi(factor(p)[1,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