\\ apply some steps to an EKG-n sequence
\\ real part = k-th term
\\ imag part = mask of previous terms
move(z, steps=1) = {
	if (z==1, return (z));	\\ EKG-1

	my (p=real(z), x=imag(z));
	for (t=1, steps,
		x += 2^p;
		for (v=2, oo,
			if (!bittest(x, v) && gcd(p,v)>1,
				p = v;
				break;
			);
		);
	);
	return (p + I*x);
}

lim = 500;
a = vector(lim);
unseen = 2

a[1] = 1;
rem--;

{
	w = vector(lim, n, n);	\\ first EKG-n sequences
	mx = lim;				\\ max value amongthe first EKG-n seqquences

	for (i=2, oo,
		\\ move
		w = apply(move, w);

		\\ extend ?
		mx = max(mx, vecmax(apply(real, w[1..lim])));
		w = concat(w, vector(mx-#w, n, move(#w+n, i-1)));

		\\ match ?
		val = Set(w);
		occ = vector(#val);
		for (j=1, #w,
			pos = setsearch(val, w[j]);
			occ[pos]++;
		);

		for (n=1, lim,
			if (!a[n],
				pos = setsearch(val, w[n]);
				if (occ[pos]>1,
					a[n] = i;
				);
			);
		);

		\\ forget duplicate sequences
		occ = vector(#occ);
		for (j=1, #w,
			pos = setsearch(val, w[j]);
			if (occ[pos]++ > 1,
				w[j] = 1;
			);
		);

		while (a[unseen],
			print (unseen " " a[unseen]);
			unseen++;
			if (unseen > #a,
				break (2);
			);
		);
	);
}

quit