This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A328686 #34 Dec 10 2019 17:45:27 %S A328686 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, %T A328686 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, %U A328686 1,0,0,2,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1 %N 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. %C A328686 For each prime, the end of the trajectory is reached when one cannot generate another prime number from it. %C A328686 For example, p(3) = 5 -> 2 (1 iteration), so a(3)=1. Also p(5) = 11 -> 5 -> 2 (2 iterations), 23 -> 11 -> 5 -> 2 (3 iterations) and 47 -> 23 -> 11 -> 5 -> 2 (4 iterations). Hence a(3) = 1, a(5) = 2, a(9) = 3 and a(15) = 4. %C A328686 a(n) = 0 for n = 1, 7, 8, 10, 11, 13, 14, 16, 19, 20, 22, 24, 25, ... The corresponding primes are A176902(n) = 2, 17, 19, 29, 31, 41, 43, ... . %C A328686 The sequence of the last terms of the trajectories begins with 2, 2, 2, 2, 2, 2, 17, 19, 2, 29, 31, 19, 41, 43, 2, 53, 29, 31, 67, ... %C A328686 The following table gives the trajectories of the smallest prime requiring 0, 1, 2, 3, 4, 5, 6, iterations: %C A328686 +------------+----------+------------------------------------------+ %C A328686 | Number of | smallest | trajectory | %C A328686 | iterations | prime | | %C A328686 +------------+----------+------------------------------------------+ %C A328686 | 0 | 2 | 2 | %C A328686 | 1 | 3 | 3 -> 2 | %C A328686 | 2 | 7 | 7 -> 3 -> 2 | %C A328686 | 3 | 13 | 13 -> 7 -> 3 -> 2 | %C A328686 | 4 | 47 | 47 -> 23 -> 11 -> 5 -> 2 | %C A328686 | 5 | 2879 | 2879 -> 1439 -> 719 -> 359 -> 179 -> 89 | %C A328686 | 6 | 1065601 | 1065601 -> 532801 -> 266401 -> 133201 -> | %C A328686 | | | 66601 -> 33301 -> 16651 | %C A328686 +------------+----------+------------------------------------------+ %e A328686 a(15) = 4 because prime(15) = 47 and 47 -> 23 -> 11 -> 5 -> 2 with 4 iterations. %p A328686 for n from 1 to 100 do: %p A328686 ii:=0:it:=0:p:=ithprime(n): %p A328686 for i from 1 to 100 while(ii=0) : %p A328686 p1:=(p-1)/2:p2:=(p+1)/2: %p A328686 if type(p1,prime)=false and type(p2,prime)=false %p A328686 then %p A328686 ii:=1:printf(`%d, `,it): %p A328686 else %p A328686 it:=it+1: %p A328686 if isprime(p1) %p A328686 then %p A328686 p:=p1: %p A328686 else %p A328686 p:=p2: %p A328686 fi: %p A328686 fi: %p A328686 od: %p A328686 od: %t A328686 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 *) %Y A328686 Cf. A000040, A005383, A005385, A176902. %Y A328686 The underlying map is A330310. %K A328686 nonn %O A328686 1,4 %A A328686 _Michel Lagneau_, Oct 25 2019