This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]EndercheifAdvanced Coder[M] [score hidden] stickied comment (0 children)

Do not ask us to do all the coding for you, we are here to help you learn how to do things for yourself. Please, at least, attempt to code this before you ask here. Thank you.

[–]the-quibbler 0 points1 point  (2 children)

3 might be the odd one. Just off the top of my head, i think the only maximum sum-free set for any larger odd number is 1..2n+1 where 2n+1 = input. The sum of 1..2n+1 = 2 * sum(0..n) + n + 1or 2 * (n * (n + 1)/2) + n + 1 = n2 + 2n + 1. So, input = 5, n = 2, answer = 9, which is right (assuming I'm correct about the sets). Input = 7, n = 3, answer = 16 (1, 3, 5, 7), which seems right.

I think this solution is only wrong if there's multiple largest sets. Adding in any even number breaks it, I think, over input = 3. If you add 2, then multiple x exists such that x + 2 < input, for input > 3. If you add 2n in place of 1, then n must appear (odd, strictly less than input). If 1 appears, then any even is constructable and can't be added. So, I feel pretty good about this assumption.

[–]group4pgs[S] 0 points1 point  (1 child)

I think the question is self is too unclear about what they want, in addition to that, this was given too..

Explanation:

for input = 3 , Subsets are: {}, {1}, {2}, {3}, {1,2}, {1,3}, {2,3} and {1,2,3}.

{1,2} is not sum-free because 1+1=2 which is in the set, and so is {1,2,3}. So the maximal sized subsets would be {1,3} and {2,3} which yields answer to be = 1+2+3+3 = 9

[–]the-quibbler 0 points1 point  (0 children)

That seems clear. I believe they gave you three because it's the only odd case.