login
The larger term of the pair (a(n), a(n+1)) is always prime.
3

%I #51 Jun 12 2024 01:17:45

%S 1,2,3,5,4,7,6,11,8,13,9,17,10,19,12,23,14,29,15,31,16,37,18,41,20,43,

%T 21,47,22,53,24,59,25,61,26,67,27,71,28,73,30,79,32,83,33,89,34,97,35,

%U 101,36,103,38,107,39,109,40,113,42,127,44,131,45,137,46,139,48,149,49,151,50,157,51,163,52,167,54,173,55,179,56,181,57

%N The larger term of the pair (a(n), a(n+1)) is always prime.

%C The sequence is started with a(1) = 1 and always extended with the smallest integer not yet present and not leading to a contradiction. The sequence is a permutation of the positive integers.

%C From _Bernard Schott_, May 15 2019: (Start)

%C Let p_k = A000040(k) and c_k = A002808(k), the data can be written:

%C 1, p_1, p_2, p_3, c_1, p_4, c_2, p_5, c_3, p_6, c_4, p_7, ...

%C At the 4th term, begins the alternating pattern:

%C {p_3, c_1, p_4, c_2, p_5, c_3, ..., p_(m+2), c_m, ...}.

%C The terms with odd index are 1, p_2, c_1, c_2, c_3, c_4, c_5, ...;

%C the terms with even index are p_1, p_3, p_4, p_5, p_6, p_7, ... This is A045344. (End)

%H Jean-Marc Falcoz, <a href="/A282649/b282649.txt">Table of n, a(n) for n = 1..6489</a>

%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>

%F From _Bernard Schott_, May 15 2019: (Start)

%F n odd: a(1) = 1, a(3) = 3, and for n >= 5, a(n) = A002808((n-3)/2).

%F n even: a(2) = 2, for n >= 4, a(n) = A000040(n/2 + 1), also,

%F n even: a(n) = A045344(n/2). (End)

%F For n > 4, if a(n-1) is prime then a(n) is the smallest composite > a(n-2); otherwise a(n) is the smallest prime > a(n-2). - _Bill McEachen_, Apr 27 2024

%e In the 1st pair of integers (1,2) the larger term is (2), which is prime;

%e in the 2nd pair of integers (2,3) the larger term is (3), which is prime;

%e in the 3rd pair of integers (3,5) the larger term is (5), which is prime;

%e in the 4th pair of integers (5,4) the larger term is (5), which is prime;

%e in the 5th pair of integers (4,7) the larger term is (7), which is prime;

%e in the 6th pair of integers (7,6) the larger term is (7), which is prime; etc.

%t a = {1}; Do[k = 1; While[Nand[PrimeQ@ Max[a[[n - 1]], k], ! MemberQ[a, k]], k++]; AppendTo[a, k], {n, 2, 120}]; a (* _Michael De Vlieger_, Feb 20 2017 *)

%Y Cf. A000040 (prime numbers), A002808 (composite numbers), A045344.

%K nonn

%O 1,2

%A _Eric Angelini_ and _Jean-Marc Falcoz_, Feb 20 2017