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

a = vector(10 000)
u = 1

nv = vector(#a)	\\ n, v, next multiple to consider, skip?
nb = 0

emit(n,v) = {
	see(v);
	a[v] = n;
	while (a[u],
		print (u " " a[u]);
		if (u++ > #a,
			quit;
		);
	);
			
	\\ remember this value
	if (2*v <= #a,
		nv[nb++] = [n, v, 2*v, 0];
	);
}

{
	emit(1,1);
	for (e=1, oo,
		w = nb;
		forstep (k=w, 1, -1,
			if (!nv[k][4],
				skip = 1;

				forstep (v=nv[k][3], #a, nv[k][2],
					if (!seen(v),
						emit(2^e+1-nv[k][1], v);
						skip = (nv[k][3] = v + nv[k][2]) > #a;
						break;
					);
				);

				nv[k][4] = skip;
			);
		);

		\\ compress
		newnb = 0;
		for (k=1, nb,
			if (!nv[k][4],
				nv[newnb++]=nv[k];
			);
		);
		nb=newnb;
	);
}

quit