OFFSET
1,9
COMMENTS
Consider the following algorithm:
Start:
If n is 1, we have finished,
Otherwise:
If n is a prime, replace it with its index among the primes, n <- A000720(n), and go back to the start.
Otherwise, if n is a composite, replace it with its index among the composites, n <- A065855(n), and go back to the start.
At some point, the process is guaranteed to reach the number 1 at which point we stop.
a(n) tells how many times a composite number was encountered in the process, before 1 was reached. This count includes also +1 for the cases where the initial n was composite at the beginning.
LINKS
Antti Karttunen, Table of n, a(n) for n = 1..32998
FORMULA
a(1) = 1, and for n >= 1, if A010051(n) = 1 [that is, when n is prime], a(n) = a(A000720(n)), otherwise a(n) = 1 + a(A065855(n)). [A000720(n) and A065855(n) tell the number of primes, and respectively, composites <= n].
a(n) = A000120(A135141(n)) - 1. [a(n) is also one less than the Hamming weight (number of 1-bits) of the n-th term of A135141].
EXAMPLE
Consider n=30. It is the 19th composite number in A002808: 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, 28, 30, ...
Thus we consider next n=19, which is the 8th prime in A000040: 2, 3, 5, 7, 11, 13, 17, 19, ...
So we proceed with n=8, which is the 3rd composite number, and then with n=3, which is the 2nd prime, and then with n=2 which is the 1st prime, and we have finished.
All in all, it took us 5 steps (A246348(30) = 6 = 5+1) to reach 1, and on the journey, we encountered two composites, 30 and 8, thus a(30) = 2.
PROG
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, Aug 27 2014
STATUS
approved