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++) a = vector(1001) forbidden = vector(2*#a, n, []) ok(n) = { \\ check for forbidden forward values for (k=1, oo, if (n-k<1, break); if (setsearch(forbidden[n+k], a[n]*a[n-k]), return (0); ); ); \\ check for products already seen for (k=1, oo, if (n-2*k<1, break); if (seen(a[n]*a[n-k]*a[n-2*k]), return (0); ); ); \\ mark forbidden forward values for (k=1, oo, if (n-k<1, break); forbidden[n+k] = setunion(forbidden[n+k], [a[n]*a[n-k]]) ); \\ mark products already seen for (k=1, oo, if (n-2*k<1, break); see(a[n]*a[n-k]*a[n-2*k]); ); return (1); } { for (n=1, #a, for (v=1, oo, a[n] = v; if (ok(n), break; ); ); print (n-1 " " a[n]); ); } quit