ispow2(n)=n>>valuation(n,2)==1; has(n)= { if (ispow2(valuation(n,2)+1), numdiv(n)==32, 0); } list(lim)= { my(v=List(),t); forprime(p=3,sqrtnint(lim\=1,31), t=p^31; if(has(t+1), listput(v,t)); if(has(t-1), listput(v,t-1))); forprime(p=3,sqrtnint(lim\27,7), my(p7=p^7); forprime(q=3,sqrtnint(lim\p7,3), if(p==q, next); t=p7*q^3; if(has(t+1), listput(v,t)); if(has(t-1), listput(v,t-1)))); forprime(p=3,sqrtnint(lim\2,15), my(p15=p^15); forprime(q=3,lim\p15, if(p==q, next); t=p15*q; if(has(t+1), listput(v,t)); if(has(t-1), listput(v,t-1)))); forprime(p=3,sqrtnint(lim\135,3), my(p3=p^3); forprime(q=3,sqrtnint(lim\(3*p3),3), if(p==q, next); my(p3q3=p3*q^3); forprime(r=2,lim\p3q3, if(p==r || q==r, next); t=p3q3*r; if(has(t+1), listput(v,t)); if(has(t-1), listput(v,t-1))))); forprime(p=3,sqrtnint(lim\15,7), my(p7=p^7); forprime(q=3,lim\(3*p7), if(p==q, next); my(p7q=p7*q); forprime(r=3,lim\p7q, if(p==r || q==r, next); t=p7q*r; if(has(t+1), listput(v,t)); if(has(t-1), listput(v,t-1))))); forprime(p=3,sqrtnint(lim\105,3), my(p3=p^3); forprime(q=3,lim\(15*p3), if(p==q, next); my(p3q=p3*q); forprime(r=3,lim\(3*p3q), if(p==r || q==r, next); my(p3qr=p3q*r); forprime(s=3,lim\p3qr, if(p==s || q==s || r==s, next); t=p3qr*s; if(has(t+1), listput(v,t)); if(has(t-1), listput(v,t-1)))))); forprime(p=3,lim\1155, forprime(q=3,lim\(105*p), if(p==q, next); my(pq=p*q); forprime(r=3,lim\(15*pq), if(p==r || q==r, next); my(pqr=pq*r); forprime(s=3,lim\(3*pqr), if(p==s || q==s || r==s, next); my(pqrs=pqr*s); forprime(o=3,lim\pqrs, if(p==o || q==o || r==o || s==o, next); t=pqrs*o; if(has(t+1), listput(v,t)); if(has(t-1), listput(v,t-1))))))); Set(v); }