OFFSET
1,1
COMMENTS
The odds-only Ulam spiral is defined with the following conventions: number k=1 (center) is at (x,y)=(0,0), 3 is at (1,0) starting shell s=1, 5 is at (1,1). Thus the spiral turns counterclockwise and the transitions from shell s to s+1 occur at the south-east diagonal.
Note that on the odds-only Ulam spiral any number k has two neighbors on the same shell s and two cross-shell. On the diagonals both cross-shell neighbors are at s+1, elsewhere they are at s-1 and s+1. The same-shell neighbors are always k-2 and k+2, except when k is the first or last member of the shell. If k is the first member of the shell s, at (s,-s+1), k+2 is same-shell and k-2 is at s-1. If k is the last member, at (s,s), k-2 is same-shell and k+2 is at s+1.
Theorem: All terms of the sequence are divisible by 3. Proof: any number k has neighbors k-2 and k+2. For an isolated composite both these neighbors are prime, hence not divisible by 3. Since exactly one of {k-2, k, k+2} is == 0 (mod 3), it must be k.
Theorem: 2 of the primes enclosing the isolated composite form a cousin prime pair. Proof: If k is an isolated composite on the odds-only Ulam spiral, k-2 and k+2 are its prime neighbors. k-2 and k+2 are at distance 4, hence cousin primes. Note that k-1 and k+1 are even and k is composite by definition.
LINKS
Paul Steendijk, Table of n, a(n) for n = 1..10000
David A. Corneth, PARI program
David A. Corneth, Part of spiral with terms in it highlighted
Paul Steendijk, Fig 1 - Isolated composites 60 shells
Paul Steendijk, Short explanation of fig 1 and fig 2
FORMULA
Number k at (x,y) is located at shell s=max(|x|,|y|). Shell s has 8*s members. The diagonals (|x|=|y|) define 4 sectors: east (-x<y<=x), north (-y<=x<y), west (x<=y<-x), and south (y<x<=-y). Defined per sector, east: k(x,y)=1+8*x^2-6*x+2*y; north: k(x,y)=1+8*y^2-2*y-2*x; west: k(x,y)=1+8*x^2-2*x-2*y; south: k(x,y)=1+8*y^2-6*y+2*x. Note that sector definitions include their downstream diagonal (east sector includes north-east diagonal, etc.).
EXAMPLE
a(1)=399 at (-7,4) in west sector. Orthogonal neighbors (see comments for calculations) are k(-8,4)=521, k(-6,4)=293, k(-7,3)=401, k(-7,5)=397, all prime.
MATHEMATICA
(* 1) Brute force method that checks all composites on the odds-only spiral. *)
spiralVal[x_, y_]:=Which[x==0&&y==0, 1, -x<y&&y<=x, 1+8x^2-6x+2y, -y<=x&&x<y, 1+8y^2-2y-2x, x<=y&&y<-x, 1+8x^2-2x-2y, True, 1+8y^2-6y+2x]
isIsolComp[x_, y_]:=With[{k=spiralVal[x, y]}, k>1&&!PrimeQ[k]&&PrimeQ[spiralVal[x, y-1]]&&PrimeQ[spiralVal[x, y+1]]&&PrimeQ[spiralVal[x-1, y]]&&PrimeQ[spiralVal[x+1, y]]]
shellCells[s_]:=Join[Table[{s, y}, {y, -s+1, s}], Table[{x, s}, {x, s-1, -s, -1}], Table[{-s, y}, {y, s-1, -s, -1}], Table[{x, -s}, {x, -s+1, s}]]
IsolComp[nMax_]:=Module[{r={}, s=0}, While[Length[r]<nMax, s++; r=Join[r, Map[spiralVal@@#&, Select[shellCells[s], isIsolComp@@#&]]]]; Take[r, nMax]]
IsolComp[43]
(* Alternative: 2) More efficient strategy using that only odd multiples of 3 are candidates and a cousin prime is required. *)
spiralVal[x_, y_]:=Which[x==0&&y==0, 1, -x<y&&y<=x, 1+8x^2-6x+2y, -y<=x&&x<y, 1+8y^2-2y-2x, x<=y&&y<-x, 1+8x^2-2x-2y, True, 1+8y^2-6y+2x]
spiralCoords[k_Integer?OddQ]:=Module[{i=(k+1)/2, s, o}, If[k==1, Return[{0, 0}]]; s=(IntegerPart[Sqrt[i-1]]+1)/2; If[(2s-1)^2+1>i, s=s-1]; o=i-(2s-1)^2-1; Which[o<2s, {s, o-s+1}, o<4s, {3s-1-o, s}, o<6s, {-s, 5s-1-o}, True, {o-7s+1, -s}]]
Select[Range[9, 150000, 6], PrimeQ[#-2]&&PrimeQ[#+2]&&With[{xy=spiralCoords[#]}, AllTrue[spiralVal@@@Map[xy+#&, {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}], PrimeQ]]&]
PROG
(PARI) \\ See Corneth link
(PARI)
\\ Brute force method that checks all composites on the odds-only spiral.
spiralVal(x, y)=if(x==0&&y==0, 1, if(-x<y&&y<=x, 1+8*x^2-6*x+2*y, if(-y<=x&&x<y, 1+8*y^2-2*y-2*x, if(x<=y&&y<-x, 1+8*x^2-2*x-2*y, 1+8*y^2-6*y+2*x))));
isIsolComp(x, y)=my(k=spiralVal(x, y)); k>1&&!isprime(k)&&isprime(spiralVal(x, y-1))&&isprime(spiralVal(x, y+1))&&isprime(spiralVal(x-1, y))&&isprime(spiralVal(x+1, y));
{IsolComp(nMax)=my(r=List(), s=0); while(#r<nMax, s++; for(y=-s+1, s, if(isIsolComp(s, y), listput(r, spiralVal(s, y)))); forstep(x=s-1, -s, -1, if(isIsolComp(x, s), listput(r, spiralVal(x, s)))); forstep(y=s-1, -s, -1, if(isIsolComp(-s, y), listput(r, spiralVal(-s, y)))); for(x=-s+1, s, if(isIsolComp(x, -s), listput(r, spiralVal(x, -s))))); Vec(r)[1..nMax]};
IsolComp(43)
(PARI)
\\ More efficient strategy using that only odd multiples of 3 are candidates and a cousin prime is required.
spiralVal(x, y)=if(x==0&&y==0, 1, if(-x<y&&y<=x, 1+8*x^2-6*x+2*y, if(-y<=x&&x<y, 1+8*y^2-2*y-2*x, if(x<=y&&y<-x, 1+8*x^2-2*x-2*y, 1+8*y^2-6*y+2*x))));
spiralCoords(k)=my(i=(k+1)/2, s, o); if(k==1, return([0, 0])); s=(sqrtint(i-1)+1)\2; if((2*s-1)^2+1>i, s=s-1); o=i-(2*s-1)^2-1; if(o<2*s, [s, o-s+1], if(o<4*s, [3*s-1-o, s], if(o<6*s, [-s, 5*s-1-o], [o-7*s+1, -s])));
isIsland(k)=my(xy=spiralCoords(k)); isprime(spiralVal(xy[1]+1, xy[2]))&&isprime(spiralVal(xy[1]-1, xy[2]))&&isprime(spiralVal(xy[1], xy[2]+1))&&isprime(spiralVal(xy[1], xy[2]-1));
{my(r=List()); forstep(j=3, 150000, 6, if(!isprime(j)&&isprime(j-2)&&isprime(j+2)&&isIsland(j), listput(r, j))); Vec(r)}
CROSSREFS
KEYWORD
nonn
AUTHOR
Paul Steendijk, May 14 2026
STATUS
approved
