OFFSET
0,3
COMMENTS
This sequence was suggested by Kevin O'Bryant, who provided terms a(0)-a(11); a(12)-a(17) were from David S. Newman.
The numbers always come in pairs, the first even, then the following odd number.
a(20) > 10^10. - Andrew Howroyd, Mar 02 2023
LINKS
Sidney Cadot, Table of n, a(n) for n = 0..19
EXAMPLE
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.
PROG
(Python)
def make_reachable(coefficients, factorials, max_k):
reachable = set([0])
for factorial in factorials:
reachable_extra = set(r + coefficient * factorial for r in reachable for coefficient in coefficients if r + coefficient * factorial <= max_k)
reachable.update(reachable_extra)
return reachable
def generate_sequence_elements(num_elements):
m = [0]
factorials = [1]
k = 1
max_k = 1
reachable = make_reachable(m, factorials, max_k)
while len(m) < num_elements:
if k > max_k:
max_k *= 2
reachable = make_reachable(m, factorials, max_k)
if factorials[-1] * (len(factorials) + 1) <= k:
factorials.append(factorials[-1] * (len(factorials) + 1))
reachable = make_reachable(m, factorials, max_k)
if k not in reachable:
m.append(k)
reachable = make_reachable(m, factorials, max_k)
k += 1
return m
print(generate_sequence_elements(20)) # Sidney Cadot, Mar 01 2023
(PARI)
Fact(lim)={my(k=1); while(k!<=lim, k++); vector(k-1, i, i!)}
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))
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}
{ upto(1200000) } \\ Andrew Howroyd, Mar 02 2023
CROSSREFS
KEYWORD
nonn,more
AUTHOR
David S. Newman, Dec 16 2010
EXTENSIONS
a(18)-a(19) from Sidney Cadot, Mar 01 2023
STATUS
approved