%I #22 Sep 17 2023 21:22:02
%S 1,2,3,4,4,5,5,6,6,7,7,8,8,8,9,10,10,11,11,12,12,12,12,13,13,13,13,14,
%T 14,15,15,15,15,15,16,17,17,17,18,19,19,20,20,20,20,20,20,21,21,21,21,
%U 22,22,23,23,24,24,24,24,25,25,25,25,26,26,27,27,27,27
%N Length of the longest subsequence of 1, ..., n on which the number of divisors function tau A000005 is nondecreasing.
%C The sequence was inspired by A365339.
%H Peter Luschny, <a href="/A365399/b365399.txt">Table of n, a(n) for n = 1..10000</a>
%H Plot2, <a href="https://oeis.org/plot2a?name1=A365399&name2=A365339&tform1=untransformed&tform2=untransformed&shift=0&radiop1=ratio&drawlines=true">A365399 vs A365339</a>.
%F a(n+1) - a(n) <= 1.
%e The terms of the subsequences of A000005 are marked by '*'. They start:
%e 1*, 2, 2 , 3, 2, 4, 2, 4, ... -> a(1) = 1
%e 1*, 2*, 2 , 3, 2, 4, 2, 4, ... -> a(2) = 2
%e 1*, 2*, 2*, 3, 2, 4, 2, 4, ... -> a(3) = 3
%e 1*, 2*, 2*, 3*, 2, 4, 2, 4, ... -> a(4) = 4
%e 1*, 2*, 2*, 3*, 2, 4, 2, 4, ... -> a(5) = 4
%e 1*, 2*, 2*, 3*, 2, 4*, 2, 4, ... -> a(6) = 5
%e 1*, 2*, 2*, 3*, 2, 4*, 2, 4, ... -> a(7) = 5
%e 1*, 2*, 2*, 3*, 2, 4*, 2, 4*, ... -> a(8) = 6
%e Example: a(2000000) = 450033.
%o (Julia)
%o # Computes the first N terms of the sequence using function tau from A000005.
%o function LLS_list(seq, N)
%o lst = zeros(Int64, N)
%o dyn = zeros(Int64, N)
%o for n in 1:N
%o p = seq(n)
%o nxt = dyn[p] + 1
%o while p <= N && dyn[p] < nxt
%o dyn[p] = nxt
%o p += 1
%o end
%o lst[n] = dyn[n]
%o end
%o return lst
%o end
%o A365399List(N) = LLS_list(tau, N)
%o println(A365399List(69))
%o (Python)
%o from bisect import bisect
%o from sympy import divisor_count
%o def A365399(n):
%o plist, qlist, c = tuple(divisor_count(i) for i in range(1,n+1)), [0]*(n+1), 0
%o for i in range(n):
%o qlist[a:=bisect(qlist,plist[i],lo=1,hi=c+1,key=lambda x:plist[x])]=i
%o c = max(c,a)
%o return c # _Chai Wah Wu_, Sep 04 2023
%Y Cf. A000005, A365339, A365398.
%K nonn
%O 1,2
%A _Peter Luschny_, Sep 03 2023