seen = 0
peen = 0

other(p) = {
	seen += 2^p;

	for (k=1, oo,
		if (!bit test(seen, k),
			my (d=abs(k-p));
			if (!bit test(peen, d) && is prime (d),
				peen += 2^d;
				return (k);
			);
		);
	);
}

{
	for (n=1, 10 000,
		a = if (n==1, 1, other(a));
		print (n " " a);
	);
}

quit