%I #18 Dec 21 2024 20:14:15
%S 0,1,3,4,5,10,7,18,9,30,11,13,15,42,17,19,60,21,23,64,25,76,27,92,29,
%T 102,31,33,114,116,118,35,130,134,138,37,154,39,174,41,43,45,184,194,
%U 47,49,51,53,224,55,57,246,59,260,61,63,264,65,276,67,292,69,304,71,316,73,332,338,75,358,77,79,81,83,85,87,404,89,414,91
%N a(n) is the least even number not used earlier and equal to the sum of the odd digits of the terms up to and including a(n), if such a number exists; otherwise, a(n) is the least odd number not occurring earlier.
%C From _M. F. Hasler_, Dec 06 2022: (Start)
%C From the definition it is immediate that any even term is equal to the sum of all odd digits in the sequence up to that term.
%C Also, the subsequences of terms of given parity are both strictly increasing: The odd terms give exactly the sequence of all odd numbers, A005408, and any even number not occurring before a given even a(n) (e.g., 2, 6, 8, 12, 14, 16, ...) will never occur in the sequence.
%C The search space to check whether an even number can extend the sequence is bounded because using a number with more digits can increase the sum of digits by at most 9 per digit, while the number itself becomes (roughly) 10 times larger with each additional digit.
%C We have the following properties:
%C 1) If the sum of all odd digits up to a(n) has only even digits, then a(n+1) equals that sum.
%C 2) An even term a(n) can never be immediately followed by a term a(n+1) with only even digits.
%C 3) An even term a(n) can be followed by another even term a(n+1) if the sum of the odd digits of a(n+1) is equal to a(n+1) - a(n), as for example at (..., 114, 116, 118, ...) and (..., 130, 134, 138, ...).
%C 4) If a(n) is even and s = (sum of the odd digits of a(n)) can be added to a(n) without changing any of a(n)'s odd digits and leaving a(n)'s even digits even, then a(n+1) <= a(n) + s. (There may be a smaller solution a(n+1) whose sum of odd digits is smaller than s.) (End)
%H Carole Dubois, <a href="/A340015/b340015.txt">Table of n, a(n) for n = 0..5001</a>
%H Eric Angelini, <a href="http://cinquantesignes.blogspot.com/2022/12/cumulative-sum-of-odd-digits_6.html">Cumulative sum of odd digits</a>, "Cinquante Signes" on blogspot.com, Dec 06 2022
%H Eric Angelini, <a href="/A340015/a340015.pdf">Cumulative sum of odd digits</a>, "Cinquante Signes" on blogspot.com, Dec 06 2022 [Cached copy]
%e The 1st nonzero even term is 4 and 4 is the sum of the odd digits so far, 1 and 3;
%e The 2nd even term is 10 and 10 is the sum of 1+3+5+1 (the last 1 being the 1 of 10 itself);
%e The 3rd even term is 18 and 10 is the sum of 1+3+5+1+7+1 (the last 1 being the 1 of 18 itself);
%e The 4th even term is 30 and 30 is the sum of 1+3+5+1+7+1+9+3 (the last 3 being the 3 of 30 itself); etc.
%o (Python)
%o def A357051_first(N=100):
%o S = []; used_even = set(); next_odd = 1; sod = 0 # sum of odd digits (so far)
%o for n in range(N):
%o x = sod + sod % 2; lim = sod + 9*len(str(x)); sodx = A071649(x)
%o while x < lim:
%o if x == sod + sodx and x not in used_even:
%o used_even |= { x } ; break
%o x += 2
%o if x % 10 == 0:
%o sodx = A071649(x)
%o if sodx == 1: lim += 9
%o else: x = next_odd; next_odd += 2; sodx = A071649(x)
%o S += [ x ] ; sod += sodx
%o return S
%o # _M. F. Hasler_, Dec 06 2022
%Y Cf. A338741, A338742, A338743, A338744, A338745, A338746.
%Y Cf. A005408 (odd numbers), A071649 (sum of odd decimal digits of n).
%K base,nonn
%O 0,3
%A _Eric Angelini_ and _Carole Dubois_, Dec 26 2020