len isdiv[] 1000035
proc sieve . .
   max = sqrt len isdiv[]
   for d = 2 to max
      if isdiv[d] = 0
         for i = d * d step d to len isdiv[]
            isdiv[i] = 1
         .
      .
   .
.
sieve
# 
proc showsx nr . .
   for i = len isdiv[] - 6 * nr downto 3
      if isdiv[i] = 0
         h = 0
         for j to nr
            h += isdiv[i + j * 6]
         .
         if h = 0
            cnt += 1
            if cnt <= 5
               s[] &= i
            .
         .
      .
   .
   print cnt & " sexy primes of " & nr + 1
   if cnt > 5
      write "... "
   .
   for i = lower 5 len s[] downto 1
      write "(" & s[i]
      for j to nr
         write " " & s[i] + j * 6
      .
      write ") "
   .
   print ""
.
proc showunsx . .
   for i = len isdiv[] - 6 downto 2
      if isdiv[i] = 0 and isdiv[i + 6] = 1 and (i <= 6 or isdiv[i - 6] = 1)
         cnt += 1
         if cnt <= 10
            s[] &= i
         .
      .
   .
   print cnt & " unsexy primes"
   write "... "
   for i = 10 downto 1
      write s[i] & " "
   .
   print ""
.
showsx 1
showsx 2
showsx 3
showsx 4
showunsx
