s = 0 unseen = 1 seen(v) = bit test(s, v) see(v) = s = bit or(s, 2^v); while (seen(unseen), unseen++) other(ppp,pp,p) = { my (f=factor(pp), v=oo); for (k=1, #f~, forstep (c=ceil(unseen/f[k,1])*f[k,1], v, f[k,1], if (!seen(c) && gcd(ppp*p,c)==1, v = min(v, c); break; ); ); ); return (v); } { a = vector(20 000); m = 1; for (n=1, oo, if (n<=3, v = unseen, v = other(ppp,pp,p); ); see(v); if (v<=#a, a[v] = n; while (a[m], print (m " " a[m]); if (m++ > #a, break (2); ); ); ); [ppp,pp,p]=[pp,p,v]; ); } quit