login
a(n) is the least k such that A342585(k) = n.
4

%I #24 Oct 12 2021 21:54:27

%S 1,2,5,9,11,21,25,30,47,39,59,71,96,100,126,115,160,178,197,217,221,

%T 261,243,265,336,322,374,419,397,479,425,485,551,583,649,618,723,653,

%U 801,690,727,887,930,974,889,932,1115,976,1260,1310,1023,1414,1070,1522

%N a(n) is the least k such that A342585(k) = n.

%C The term after the n-th 0 in A342585 is the running total of 0's, and there are infinitely many 0's, so all nonnegative integers appear in A342585. - _Peter Munn_, May 08 2021

%H Rémy Sigrist, <a href="/A343878/b343878.txt">Table of n, a(n) for n = 0..10000</a>

%H Rémy Sigrist, <a href="/A343878/a343878.gp.txt">PARI program for A343878</a>

%F For n >= 1, a(n) <= A343880(n) + 1. - _Peter Munn_, May 08 2021

%e We have:

%e n: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21

%e A342585: 0, 1, 1, 0, 2, 2, 2, 0, 3, 2, 4, 1, 1, 0, 4, 4, 4, 1, 4, 0, 5

%e So:

%e - a(0) = 1, a(1) = 2, a(2) = 5, a(3) = 9, a(4) = 11, a(5) = 21.

%t Block[{a, c, k, m, nn = 54}, c[0] = 1; a = {0}~Join~Reap[Do[k = 0; While[IntegerQ[c[k]], Set[m, c[k]]; Sow[m]; If[IntegerQ@ c[m], c[m]++, c[m] = 1]; k++]; Sow[0]; c[0]++, nn]][[-1, -1]]; TakeWhile[Array[FirstPosition[a, #][[1]] &, nn, 0], IntegerQ]] (* _Michael De Vlieger_, Oct 12 2021 *)

%o (PARI) See Links section.

%o (Python)

%o def A343878(n):

%o k, c = 0, dict()

%o while True:

%o m, r = 0, 1

%o while r > 0:

%o k += 1

%o r = c.get(m,0)

%o if n == r:

%o return k

%o c[r] = c.get(r,0)+1

%o m += 1 # _Chai Wah Wu_, Aug 31 2021

%Y Cf. A342585, A343880.

%Y For records see A347305.

%K nonn,look,easy

%O 0,2

%A _Rémy Sigrist_, May 02 2021

%E Name shortened by _Peter Munn_, May 08 2021