|
MATHEMATICA
|
NextPrime[ n_Integer ] := Module[ {k = n + 1}, While[ ! PrimeQ[ k ], k++ ]; Return[ k ] ]; PrevPrime[ n_Integer ] := Module[ {k = n - 1}, While[ ! PrimeQ[ k ], k-- ]; Return[ k ] ]; p = 0; Do[ a = Table[ -1, {n} ]; k = Max[ 1, p ]; While[ Union[ a ] != {5}, k = NextPrime[ k ]; a = Take[ AppendTo[ a, Mod[ k, 8 ] ], -n ] ]; p = NestList[ PrevPrime, k, n ]; Print[ p[[ -2 ] ] ]; p = p[[ -1 ] ], {n, 1, 9} ]
Prime[#[[1, 1]]]&/@Table[SequencePosition[Table[If[Mod[Prime[n], 8]==5, 1, 0], {n, 6*10^6}], PadRight[{}, i, 1], 1], {i, 10}] (* The program uses the SequencePosition function from Mathematica version 10. It generates only the first ten terms. It could be modified to generate more but it would take increasingly lengthy times to generate the higher terms. *)
|