A328686 Define a map from the primes to the primes by f(p) = (p-1)/2 if that is prime, or else (p+1)/2 if that is prime, and otherwise is undefined. Start with the n-th prime and iterate f until we cannot go any further; a(n) is the number of steps.
0, 1, 1, 2, 2, 3, 0, 0, 3, 0, 0, 1, 0, 0, 4, 0, 1, 1, 0, 0, 2, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1
Offset: 1
Keywords
Examples
a(15) = 4 because prime(15) = 47 and 47 -> 23 -> 11 -> 5 -> 2 with 4 iterations.
Programs
-
Maple
for n from 1 to 100 do: ii:=0:it:=0:p:=ithprime(n): for i from 1 to 100 while(ii=0) : p1:=(p-1)/2:p2:=(p+1)/2: if type(p1,prime)=false and type(p2,prime)=false then ii:=1:printf(`%d, `,it): else it:=it+1: if isprime(p1) then p:=p1: else p:=p2: fi: fi: od: od:
-
Mathematica
f[p_] := If[PrimeQ[(q = (p-1)/2)], q, If[PrimeQ[(r = (p+1)/2)], r, 0]]; g[n_] := -2 + Length @ NestWhileList[f, n, #>0 &]; g /@ Select[Range[457], PrimeQ] (* Amiram Eldar, Nov 16 2019 *)
Comments