Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.
%I #83 Apr 05 2020 13:26:25
%S 1,2,3,4,5,6,7,8,9,1,2,4,5,6,8,9,11,21,32,33,43,44,74,57,85,68,96,89,
%T 79,8,11,21,22,42,44,54,95,69,7,8,11,21,32,33,43,44,74,57,85,68,96,89,
%U 79,8,9,1,4,6,7,8,11,21,22,42,44,54,95,69,7,8,11,21
%N a(1) = 1. Thereafter, if n is prime, a(n) is the next prime after a(n-1), but written backwards. If n is not prime, a(n) is the next composite after a(n-1), written backwards.
%C The first two-digit a(n) occurs at n = 17. The first three-digit a(n) occurs at n = 643. According to _Michel Marcus_, in the first 10^8 terms, a(n) never exceeds 909. It is now known that this is the maximal value (see the Weimholt link).
%C Since prime gaps (A001223) do not become periodic, this sequence should not become periodic either, though several short series of terms (e.g., 11, 21, 22, 42, 44, 54, 95, 69) reappear frequently.
%C From _Rémy Sigrist_, Sep 12 2019: (Start)
%C For any n > 0:
%C - let c(n) be the next composite after n, read backwards,
%C - let p(n) be the next prime after n, read backwards.
%C Let C be the set defined by the following rules:
%C - 2 belongs to C,
%C - if x belongs to C, then c(c(x)) and c(p(x)) also belong to C.
%C We can prove by program that the set C is finite.
%C Hence:
%C - for any even number n >= 2, a(n) <= max(C) = 939,
%C - for any odd number n >= 3, a(n) <= max({c(k), k in C} U {p(k), k in C}) = 938.
%C Hence the sequence is bounded, and A326298 and A326402 are finite.
%C (End)
%C From _M. F. Hasler_, Sep 13 2019: (Start)
%C Terms a(n) > 800 occur at indices (649, 3132, [3595], 3596, [6805], 6806, 7344, 8233, [8234], [11173], 11174, 12619, 13687, 14089, ...). (Subsequent indices are > 20000. Indices in [.] correspond to a non-maximal value, i.e., a(n+-1) > a(n).) The corresponding values are in the set {804, 806, 807, 808, 809, 904, 907} and occur as part of one of the following subsequences: (maxima starred)
%C a) (..., 66, 86, 98, 99, 101, 201, 202, 302, 703, 407, 804*, 508, 15, 61, 26, ...)
%C b) (..., 66, 86, 98, 99, 101, 201, 202, 302, 303, 403, 904*, 509, 15, 61, ...)
%C c) (..., 201, 202, 302, 303, 403, 404, 504, 505, 605, 606, 806*, 708, 17, 81, 28, 92, 39, ...)
%C d) (..., 302, 303, 403, 404, 504, 505, 605, 706, 707, 807, 808*, 18, 2, 4, 6, 8, 9, 1, 4, ...),
%C e) (..., 302, 303, 403, 404, 504, 505, 605, 706, 707, 907*, 809, 18, 2, 3, 4, 6, 8, 9, 1, ...).
%C (End)
%H Max Tohline, <a href="/A326344/b326344.txt">Table of n, a(n) for n = 1..20000</a>
%H Rémy Sigrist, <a href="/A326344/a326344.gp.txt">PARI program that computes the set C described in comments</a>
%H Andrew Weimholt, <a href="/A326344/a326344.txt">Proof that A326344 is bounded with a maximum value of 909</a>
%p c:= n-> (k-> `if`(isprime(k), c(k), k))(n+1):
%p a:= proc(n) option remember; `if`(n=1, 1,
%p (s-> parse(cat(s[-i]$i=1..length(s))))(""||(
%p `if`(isprime(n), nextprime(a(n-1)), c(a(n-1))))))
%p end:
%p seq(a(n), n=1..100); # _Alois P. Heinz_, Sep 12 2019
%t ncp[{n_,a_}]:=Module[{k=1},{n+1,If[PrimeQ[n+1],IntegerReverse[NextPrime[ a]],While[!CompositeQ[k+a],k++];IntegerReverse[k+a]]}]; NestList[ncp,{1,1},80][[All,2]] (* Requires Mathematica version 10 or later *) (* _Harvey P. Dale_, Apr 05 2020 *)
%o (PARI) nextcompo(n) = while(isprime(n), n++); n;
%o lista(nn) = {my(a = 1); for (n=2, nn, print1(a, ", "); if (isprime(n), a = nextprime(a+1), a = nextcompo(a+1)); a = fromdigits(Vecrev(digits(a))););} \\ _Michel Marcus_, Sep 11 2019
%o (PARI) A326344_vec(N) = vector(N,n,N=A004086(if(n<=9,n,isprime(n),nextprime(N+1),N>3,N+2^isprime(N+1),4))) \\ Next composite is N+1 if this is composite, else N+2 (unless N=1). A004086(n)=fromdigits(Vecrev(digits(n))). - _M. F. Hasler_, Sep 13 2019
%Y For records see A326298 and A326402.
%Y Cf. A000027 (the positive integers: this sequence without the digit-reversal, as observed by _Michel Marcus_).
%Y For analogs in bases 3, 6, and 7 see A326894, A327463, and A327241.
%Y For analogs in bases 3,5,6,7,10 see A326894, A327464, A327463, A327241, A326344 = the present sequence.
%Y Cf. A000040, A002808, A004086, A113646, A151800, A326892.
%K nonn,base,nice
%O 1,2
%A _Max Tohline_, Sep 11 2019