%I #16 Oct 24 2020 10:53:44
%S 0,1,2,3,4,5,6,7,7,8,9,9,10,10,11,11,12,12,13,14,14,15,15,16,16,17,17,
%T 17,18,18,19,19,19,20,20,20,21,21,21,22,22,22,23,23,23,24,24,24,25,25,
%U 25,25,26,26,26,26,26,27,27,27,27,28,28,28,28,28,29,29
%N Define a map f(n):= n-> n + pi(n) - pi(n + pi(n)), where pi(n) is the prime count of n (n>=1). a(n) is the number of steps for n to reach 1 under repeated iteration of f.
%C For any integer n > 1, pi(n + pi(n)) > pi(n) according to Lu and Deng (see Links). Thus, n + pi(n) - pi(n + pi(n)) < n, which means n is reduced by at least 1 every time map f is applied, eventually reaching 1 under repeated iteration of f.
%C It seems that the sequence contains all nonnegative integers.
%H Alois P. Heinz, <a href="/A337979/b337979.txt">Table of n, a(n) for n = 1..10000</a>
%H Ya-Ping Lu and Shu-Fang Deng, <a href="https://arxiv.org/abs/2007.15282">An upper bound for the prime gap</a>, arXiv:2007.15282 [math.GM], 2020.
%F f^a(n) (n) = 1, where f = A062298(A095117) and m-fold iteration of f is denoted by f^m.
%e a(1) = 0 because f^0(1) = 1;
%e a(2) = 1 because f(2) = 2 + pi(2) - pi(2 + pi(2)) = 1;
%e a(4) = 3 because f^3(4) = f^2(f(4)) = f^2(3) = f(f(3)) = f(2) = 1.
%p a:= proc(n) option remember; `if`(n=1, 0, 1+a((
%p pi-> n+pi(n)-pi(n+pi(n)))(numtheory[pi])))
%p end:
%p seq(a(n), n=1..80); # _Alois P. Heinz_, Oct 24 2020
%t f[n_] := Module[{x = n + PrimePi[n]}, x - PrimePi[x]];
%t a[n_] := Module[{nb = 0, m = n}, While[m != 1, m = f[m]; nb++]; nb];
%t Array[a, 100] (* _Jean-François Alcover_, Oct 24 2020, after PARI code *)
%o (Python)
%o from sympy import primepi
%o print(0)
%o n = 2
%o for n in range (2, 10000001):
%o ct = 0
%o n_l = n
%o pi_l = primepi(n)
%o while ct >= 0:
%o n_r = n_l + pi_l
%o pi_r = primepi(n_r)
%o n_l = n_r - pi_r
%o pi_l = primepi(n_l)
%o ct += 1
%o if n_l == 1:
%o print(ct)
%o break
%o (PARI) f(n) = {my(x = n + primepi(n)); x - primepi(x);} \\ A337978
%o a(n) = {my(nb=0); while (n != 1, n = f(n); nb++); nb;} \\ _Michel Marcus_, Oct 06 2020
%Y Cf. A000720, A025003, A062298, A095117, A337978.
%K nonn
%O 1,3
%A _Ya-Ping Lu_, Oct 05 2020