OFFSET
0,5
COMMENTS
As long as we have a number whose decimal representation is the concatenation of a prime number, say the k-th prime number, and a minimal string possibly empty or with leading zeros, say v, we replace this number with the concatenation of k and v; eventually none of the prefixes will be a prime number.
LINKS
Rémy Sigrist, Table of n, a(n) for n = 0..10000
FORMULA
EXAMPLE
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.
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 *)
PROG
(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
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, Nov 30 2019
STATUS
approved