%I #51 Mar 03 2023 08:35:33
%S 0,1,4,5,22,23,82,83,466,467,478,479,1090486,1090487,1090774,1090775,
%T 1090846,1090847,1199566,1199567
%N a(0)=0; for n >= 1, a(n) is the least positive integer that cannot be written in the form Sum_{k>=1} s(k)*k!, with s(k) in {a(0), a(1), ..., a(n-1)}.
%C This sequence was suggested by Kevin O'Bryant, who provided terms a(0)-a(11); a(12)-a(17) were from _David S. Newman_.
%C The numbers always come in pairs, the first even, then the following odd number.
%C a(20) > 10^10. - _Andrew Howroyd_, Mar 02 2023
%H Sidney Cadot, <a href="/A141447/b141447.txt">Table of n, a(n) for n = 0..19</a>
%e When a(0) = 0 and a(1) = 1, the numbers from 1 to 3 may be written 1 = 1*1!, 2 = 1*2!, 3 = 1*1! + 1*2!, but there is no way to write 4 as a sum having the required form, so a(2) = 4.
%o (Python)
%o def make_reachable(coefficients, factorials, max_k):
%o reachable = set([0])
%o for factorial in factorials:
%o reachable_extra = set(r + coefficient * factorial for r in reachable for coefficient in coefficients if r + coefficient * factorial <= max_k)
%o reachable.update(reachable_extra)
%o return reachable
%o def generate_sequence_elements(num_elements):
%o m = [0]
%o factorials = [1]
%o k = 1
%o max_k = 1
%o reachable = make_reachable(m, factorials, max_k)
%o while len(m) < num_elements:
%o if k > max_k:
%o max_k *= 2
%o reachable = make_reachable(m, factorials, max_k)
%o if factorials[-1] * (len(factorials) + 1) <= k:
%o factorials.append(factorials[-1] * (len(factorials) + 1))
%o reachable = make_reachable(m, factorials, max_k)
%o if k not in reachable:
%o m.append(k)
%o reachable = make_reachable(m, factorials, max_k)
%o k += 1
%o return m
%o print(generate_sequence_elements(20)) # _Sidney Cadot_, Mar 01 2023
%o (PARI)
%o Fact(lim)={my(k=1); while(k!<=lim, k++); vector(k-1, i, i!)}
%o Scan(lim, F, S)=my(b=2^lim); for(i=1, #F, my(f=F[i], t=0); for(j=1, #S, my(s=f*S[j]); if(s && s<=lim, t=bitor(t, b>>s))); b=bitor(b,t)); b=2^(lim+1)-1-b; if(!b, 0, lim-logint(b,2))
%o upto(lim) = {my(S=[0], t=0, b=0); while(t || b<lim, if(t, S=concat(S,t), b=min(lim,2*b+1)); t=Scan(b, Fact(b), S)); S}
%o { upto(1200000) } \\ _Andrew Howroyd_, Mar 02 2023
%K nonn,more
%O 0,3
%A _David S. Newman_, Dec 16 2010
%E a(18)-a(19) from _Sidney Cadot_, Mar 01 2023