As before , Charlotte selected a subset out of the integers from 1 through 20. None of the numbers in the subset is double another number in the subset.
What is the maximum possible sum of these numbers in
Bonus : Can you generalize your answer for a subset out of the integers from 1 through
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Basic idea
As in the solution of this problem , we partition all integers 1 , … , 2 0 into groups that differ by factors of two:
2 0 1 9 1 8 1 7 1 6 1 5 1 4 1 3 1 2 1 1 1 0 9 8 7 6 5 4 3 2 1
At best, we can take every other element from each row. To maximize the sum, we take the first, third, and fifth column. The required sum is therefore X 2 0 = 2 0 + 1 9 + 1 8 + 1 7 + 1 6 + 1 5 + 1 4 + 1 3 + 1 2 + 1 1 + 5 + 4 + 3 + 1 = 1 6 8 .
Quicker count
For a quicker count, let T n = ∑ i = 1 n = 2 1 n ( n + 1 ) be the n th triangle number. We realize that the required sum is X 2 0 = ( 1 + ⋯ + 2 0 ) − ( 1 + ⋯ + 1 0 ) + ( 1 + ⋯ + 5 ) − ( 1 + ⋯ + 2 ) + 1 = T 2 0 − T 1 0 + T 5 − T 2 + T 1 = 2 1 0 − 5 5 + 1 5 − 3 + 1 = 1 6 8 .
General solution
In general, given the number N we see that the solution is X N = T N − T ⌊ N / 2 ⌋ + T ⌊ N / 4 ⌋ − T ⌊ N / 8 ⌋ + ⋯
Cute little formula
We also have X N = 1 5 6 N 2 + 5 N + 3 s N + a N . Here, a N and s N are defined in terms of the binary digits of N = ⋯ b 4 b 3 b 2 b 1 b 0 2 . a N is the alternating digit sum , a N = b 0 − b 1 + b 2 − b 3 + − ⋯ = j = 0 ∑ ∞ ( − ) j b j ; for s N I have no fancy name, but it is defined as s N = b 0 N − b 1 ⌊ 2 N ⌋ + b 2 ⌊ 4 N ⌋ − b 3 ⌊ 8 N ⌋ + − ⋯ = b 0 ( b 0 + 2 b 1 + 4 b 2 + ⋯ ) − b 1 ( b 1 + 2 b 2 + 4 b 3 + ⋯ ) + b 2 ( b 2 + 2 b 3 + 4 b 4 + ⋯ ) − + ⋯ = j = 0 ∑ ∞ ( − ) j b j k = 0 ∑ ∞ 2 k b j + k .
In the case of N = 2 0 = 1 0 1 0 0 2 , we have a 2 0 s 2 0 = 0 − 0 + 1 − 0 + 1 = 2 ; = 0 ⋅ 2 0 − 0 ⋅ 1 0 + 1 ⋅ 5 − 0 ⋅ 2 + 1 ⋅ 1 = 6 ; so that X 2 0 = 1 5 6 ⋅ 4 0 0 + 5 ⋅ 2 0 + 3 ⋅ 6 + 2 = 1 5 2 5 2 0 = 1 6 8 .
Proof of cute little formula
By induction on the binary digits of N . Write N = 2 n + b , with b = 0 or 1 . Then we have
X N a N s N = T N − X n ; = b − a n ; = b N − s n .
Since X 0 = a 0 = s 0 = 0 , the formula is obviously true for X 0 = 0 (Base Step).
For the Induction Step, suppose the formula applies to n ; we multiply by 30 to get 3 0 X n = 1 2 n 2 + 1 0 n + 6 s n + 2 a n . Then 3 0 X N = 3 0 T N − 3 0 X n = 1 5 ( 2 n + b ) ( 2 n + b + 1 ) − ( 1 2 n 2 + 1 0 n + 6 s n + 2 a n ) = 6 0 n 2 + 6 0 b n + 1 5 b 2 + 3 0 n + 1 5 b − 1 2 n 2 − 1 0 n − 6 s n − 2 a n = 1 2 ( 4 n 2 + 4 b n + b 2 ) + 1 0 ( 2 n + b ) + 6 ( b ( 2 n + b ) − s n ) + 2 ( b − a n ) = 1 2 N 2 + 1 0 N + 6 s N + 2 a N , note that b 2 = b as we needed to show.
So how did I find this little formula? I realized that X N = 2 1 ( N 2 − ⌊ N / 2 ⌋ 2 + ⌊ N / 4 ⌋ 2 − + ⋯ ) + 2 1 ( N − ⌊ N / 2 ⌋ + ⌊ N / 4 ⌋ − + ⋯ ) = : 2 1 Q N + 2 1 R N , and since I already calculated R n = 3 1 ( 2 N + a N ) in a previous problem, I focused on the quadratic sum Q N .
I realized that for N = 2 m the sum would become Q N = 4 m − 4 m − 1 + − ⋯ ± 1 = 5 1 ( 4 m + 1 ± 1 ) ≈ 5 4 N 2 . Therefore I compared side-by-side the values of 5 Q N and 4 N 2 and looked at their differences:
N 1 2 3 4 5 6 7 8 9 1 0 Q N 1 3 8 1 3 2 2 2 8 4 1 5 1 6 8 7 8 5 Q N 5 1 5 4 0 6 5 1 1 0 1 4 0 2 0 5 2 5 5 3 4 0 3 9 0 4 N 2 4 1 6 3 6 6 4 1 0 0 1 4 4 1 9 6 2 5 6 3 2 4 4 0 0 δ N = 5 Q N − 4 N 2 + 1 − 1 + 4 + 1 + 1 0 − 4 + 9 − 1 + 1 6 − 1 0
The column δ n showed some nice regularities, e.g. δ 2 n = − δ n and δ 2 n + 1 = 4 n + 1 − δ n . A little further study shows that for N = 2 n + b , δ N = ( 2 N − 1 ) b − δ n ; splitting δ N = 2 s N − a N gave me the recursion definitions above, from which I derived the recipe for calculating s N .
Finally, putting everything together, X N = 2 1 Q N + 2 1 R N = 2 1 ⋅ 5 4 N 2 + δ N + 2 1 ⋅ 3 2 N + a N = 3 0 3 ( 4 N 2 + 2 s N − a N ) + 5 ( 2 N + a N ) = 3 0 1 2 N 2 + 1 0 N + 6 s N + 2 a N .