[go: up one dir, main page]

login
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.
3
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,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.
FORMULA
a(n) <= n with equality iff n belongs to A202259.
a(prime(k)) = a(k) for any k > 0 where prime(k) denotes the k-th prime number.
a(10*k + v) = 10*a(k) + v for any k > 0 and v in {0, 2, 4, 5, 6, 8}.
a(A007097(k)) = 1 for any k >= 0.
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
See A327539 for similar sequences.
Sequence in context: A115607 A318876 A330356 * A288469 A076717 A200360
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, Nov 30 2019
STATUS
approved