%I #12 Mar 16 2024 17:26:36
%S 1,3,2,10,4,52,5,43,6,54,7,65,8,76,9,103,11,99,12,110,13,121,14,132,
%T 15,143,16,154,17,165,18,176,19,187,20,198,21,209,22,220,23,231,24,
%U 242,25,253,26,264,27,275,28,286,29,297,30,308,31,319,32,330,33,341
%N Lexicographically earliest sequence of distinct positive integers such that for any n > 0, a(1) + ... + a(n) is a multiple of n, and the least value not yet in the sequence appears as soon as possible.
%C To build the sequence:
%C - we start with a(1) = 1,
%C - once we have n terms, let v be the least value not yet in the sequence,
%C - if a(1) + ... a(n) + v is a multiple of n+1, then a(n+1) = v,
%C - otherwise a(n+2) = v and a(n+1) is chosen as small as possible so as to meet the required conditions (this is always possible as n+1 and n+2 are coprime).
%C The construction is similar to that of A367288.
%C This sequence is a variant of A019444 and, by design, is guaranteed to be a permutation of the nonnegative integers (with inverse A371221).
%H Rémy Sigrist, <a href="/A371220/b371220.txt">Table of n, a(n) for n = 1..10000</a>
%H Rémy Sigrist, <a href="/A371220/a371220.gp.txt">PARI program</a>
%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>
%e The first terms, alongside the average of the first terms, are:
%e n a(n) (a(1)+...+a(n))/n
%e -- ---- -----------------
%e 1 1 1
%e 2 3 2
%e 3 2 2
%e 4 10 4
%e 5 4 4
%e 6 52 12
%e 7 5 11
%e 8 43 15
%e 9 6 14
%e 10 54 18
%e 11 7 17
%e 12 65 21
%o (PARI) See Links section.
%Y Cf. A019444, A367288, A371221 (inverse).
%K nonn
%O 1,2
%A _Rémy Sigrist_, Mar 15 2024