OFFSET
0,3
COMMENTS
In other words, a(n) is the maximum sum of a Sidon set whose elements are <= n.
a(n) is also the maximum sum of a subset of {1..n} such that every pair of distinct elements has a distinct difference.
LINKS
EXAMPLE
a(0) = 0 = sum of {}.
a(1) = 1 = sum of {1}.
a(2) = 3 = sum of {1,2}.
a(3) = 5 = sum of {2,3}.
a(4) = 8 = sum of {1,3,4}.
a(5) = 11 = sum of {2,4,5}.
a(12) = 37 = sum of {6,8,11,12} or {5,9,11,12}.
a(20) = 78 = sum of {2,8,12,17,19,20}.
See also the examples in A143823.
PROG
(PARI)
a(n)={
my(recurse(k, b, w)=
if(k > n, 0,
my(s=self()(k+1, b, w));
b+=1<<k; if(!bitand(w, b<<k), s=max(s, k+self()(k+1, b, w + (b<<k))));
s)
);
recurse(1, 0, 0);
}
(Python)
def a(n):
def recurse(k, b, w):
if k > n: return 0
s = recurse(k+1, b, w)
b += (1<<k)
if not w & (b<<k): s = max(s, k+recurse(k+1, b, w+(b<<k)))
return s
return recurse(1, 0, 0)
print([a(n) for n in range(40)]) # Michael S. Branicky, Oct 27 2024 after Andrew Howroyd
CROSSREFS
KEYWORD
nonn
AUTHOR
Andrew Howroyd, Oct 27 2024
STATUS
approved