A329428 Starting from n: as long as the decimal representation starts with a prime number, replace the largest such prefix with the index of the corresponding prime number; a(n) corresponds to the final value.
0, 1, 1, 1, 4, 1, 6, 4, 8, 9, 10, 1, 12, 6, 14, 15, 16, 4, 18, 8, 10, 1, 12, 9, 14, 15, 16, 4, 18, 10, 10, 1, 12, 9, 14, 15, 16, 12, 18, 10, 40, 6, 42, 14, 44, 45, 46, 15, 48, 49, 10, 1, 12, 16, 14, 15, 16, 12, 18, 4, 60, 18, 62, 63, 64, 65, 66, 8, 68, 69, 40
Offset: 0
Examples
For n = 991: - let pi denote A000720, - 991 gives pi(991) = 167, - 167 gives pi(167) = 39, - 39 gives pi(3) followed by 9 = 29, - 29 gives pi(29) = 10, - neither 1 nor 10 is a prime number, so a(991) = 10.
Links
- Rémy Sigrist, Table of n, a(n) for n = 0..10000
- Rémy Sigrist, Scatterplot of the ordinal transform of the first 1000000 terms
Programs
-
Mathematica
Array[Which[# == 0, 0, # == 1, 1, True, FixedPoint[If[! IntegerQ@ #1, FromDigits[#2], FromDigits[Join @@ {IntegerDigits@ PrimePi@ #1, Drop[#2, IntegerLength@ #1]}]] & @@ {SelectFirst[Table[FromDigits[#[[1 ;; i]]], {i, Length@ #, 1, -1}], PrimeQ], #} &@ IntegerDigits[#] &, #]] &, 71, 0] (* Michael De Vlieger, Dec 01 2019 *) f[n_]:=Block[{p,r,d = IntegerDigits@ n,v=n}, Do[{p,r}= FromDigits/@ TakeDrop[d,k]; If[PrimeQ@ p, v=PrimePi[p] 10^(Length[d]-k)+r; Break[]],{k, Length@d, 1, -1}]; v]; a[n_]:= FixedPoint[f, n]; Array[a,71,0] (* Giovanni Resta, Dec 02 2019 *)
-
PARI
t(n) = if (n==0, 0, isprime(n), primepi(n), 10*t(n\10)+(n%10)) a(n) = while (n!=n=t(n),); n
Comments