allocate mem(2^30) big = 1 000 000 s = 0 S = Set([]) unseen = 1 seen(v) = if (v < big, bit test(s, v), set search(S, v)) see(v) = if (v < big, s = bit or(s, 2^v), S = set union(S, Set([v]))); while (seen(unseen), unseen++) other(k) = { if (k>10^50, for (v=unseen, 10^6, if (!seen(v) && k%v==0, return (v); ); ); ); fordiv (k, d, if (!seen(d), return (d); ); ); print ("# the end"); quit } { base = 10; for (n=1, oo, if (n==1, v=1, n==2, v=2, v=other(pp*base^#digits(p, base)+p); ); see(v); print (n " " v); [pp,p]=[p,v]; ); } quit