# Divide the numbers 1,2,…,n into two sets of equal sum. [duplicate]

This question already has an answer here:

My approach:

If sum(1 to n) is divisible by 2, then it is possible to divide the set.

If n is even take 1st and last element and add to 1st set, then add 2nd and 2nd last to 2nd set...and so on, In then end to balance out both set I remove 1 from 1st set and add it to 2nd.

I don't know how to do it if n is odd.

For odd: eg: n=7
4
1 2 4 7 = 14
3
3 5 6 = 14


## marked as duplicate by lulu, John Omielan, José Carlos Santos, YuiTo Cheng, Lord Shark the UnknownJun 19 at 0:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

• I think you misunderstood, Sum(1)=1 and Sum(2)=1+2=3 both are not divisible by 2 so it's not possible for these 2 sets. – Het Jun 18 at 14:48
• @AlexanderGeldhof, Yes when the sum is divsible by 2, and n is odd. – Het Jun 18 at 14:51
• yes, thank you. I didn't see it. – Het Jun 18 at 14:57
• @lulu, I am specifically asking to divide into 2 set only, The link posted is for k set, Could be difficult to understand. I think you should remove the duplicate marker. – Het Jun 18 at 15:01
• Your claim is a special case of the general claim, and the general claim is not especially difficult. I don't see any reason to isolate this case... – lulu Jun 18 at 15:06

## 4 Answers

This is essentially @Alexander Geldhof ideas.

We need to deal with the case when $$n$$ is odd and the sum $$\sum_{i=1}^n i=\frac{n(n+1)}{2}$$ being even. Note that these two conditions are equivalent to say that $$n\equiv 3\mod 4$$.

So, we need to prove the proposition for $$n\equiv 3\mod 4$$. Let's do it by induction.

Initial case $$n=3$$: Easily we can split $$A=\{1,2\}$$ $$B=\{3\}$$.

Inductive step $$n\to n+4$$:

Suppose we can split the set $$\{1,\dots,n\}$$ into two sets $$A$$,$$B$$ with the same sum. Then, we can split $$\{1,\dots,n+4\}$$ into the sets $$A\cup \{n+1,n+4\}$$ and $$B\cup\{n+2,n+3\}$$ note that these sets will remain with the same sum since $$(n+1)+(n+4)=(n+2)+(n+3)$$.

So the induction is complete.

Remark: In the case when $$n$$ is even and $$\sum_{i=1}^ni$$ is even, we conclude $$n\equiv 0\mod 4$$. The induction works as well with the initial case $$n=4$$, $$A=\{1,4\}$$, $$B=\{2,3\}$$.

• n%2==1 and (n(n+1)/2)%2==0 is equivalent to n%4==3, How? – Het Jun 18 at 16:31
• @Het, $n$ is odd so $n((n+1)/2)$ will be even only if $(n+1)/2$ is even, i.e. when $n+1$ is multiple of $4$. – Julian Mejia Jun 18 at 16:45
• So if A={1,2} and B={3} then it'd work for every n (where n=3mod4), right? – Het Jun 18 at 17:02
• @Het, Yes, just use the induction step to get it for any $n=3\mod 4$. For instance from $n=3$ you have $A=\{1,2\}$, $B=\{3\}$. Using the induction step you get that for $n=3+4=7$ you can split it in $A=\{1,2,4,7\}$ and $B=\{3,5,6\}$. If you repeat the induction step you get $n=7+4=11$ you can split it in $A=\{1,2,4,7,8,11\}$ and $B=\{3,5,6,9,10\}$ and so on. – Julian Mejia Jun 18 at 17:09

First we know that there is no solution for $$n=1$$ nor for $$n=2$$. For $$n=3$$, we can form the sets $$\{1, 2\}$$ and $$\{3\}$$. For $$n=4$$, as you said, we can apply Gauss's method by forming the sets $$\{1, 4\}$$ and $$\{2, 3\}$$. If $$n=5$$, there is no solution, nor for $$n=6$$. However, for $$n=7$$, we can form the sets $$\{1, 2, 4, 7\}$$ and $$\{3, 5, 6\}$$. So now we have two possibilities: if $$n-3$$ is divisible by four, we can form the two sets $$\{1, 2\}$$ and $$\{3\}$$ and then apply Gauss's method starting with $$4$$: add $$4$$ and $$n$$ to one set, then $$5$$ and $$n-1$$, and so on. If $$n$$ is divisible by four, we can apply Gauss's method immediately.

Note that the numbers for which the sum is even, and $$n$$ is odd, are exactly $$n = \{3, 7, 11, \ldots \}$$. It's clear how to divide the 3-set up. To divide the 7-set up, assign (4 and 7) to the first set and (5 and 6) to the second set. Continue this inductively.

• I din't get it. Can you please elaborate the algorithm for odd n when sum is even. – Het Jun 18 at 15:33
• For $n = 3$, P = 1,2 and Q = 3. For $n = 7$, P = 1,2,4,7 and Q = 3, 5, 6. For $n = 11$, P = 1, 2, 4, 7, 8, 11 and Q = 3, 5, 6, 9, 10. Does this clarify matters? – Alexander Geldhof Jun 18 at 15:35
• I still didn't get it, how to generalize it for n (odd), How are you deciding which number will go to which set? – Het Jun 18 at 15:45
• Note that we're adding 4 numbers each time ((4,5,6,7) the first time and (8,9,10,11) the second time). You add the first and the fourth of those to one set, and second and third to the other. – Alexander Geldhof Jun 18 at 15:47
• It is crucial that you realise that sum = even and n = odd implies that $n = 4\cdot k + 3$, $k \in \mathbb{N}$ for this argument to work – Alexander Geldhof Jun 18 at 15:48

A triangular number is even if and only if its argument is $$\in\{0,3\}\bmod 4$$.

If the argument is $$\equiv 0\bmod 4$$, you can specify blocks from the "outside in". For $$n=8$$ you put $$1$$ and $$8$$ into one block, then $$2$$ and $$7$$ into the second block, and alternate blocks until you hit the middle:

$$1+2+3+4+5+6+7+8=\color{blue}{1+8}\color{brown}{+2+7}\color{blue}{+3+6}\color{brown}{+4+5}$$

$$=\color{blue}{1+3+6+8}\color{brown}{+2+4+5+7}$$

For an argument $$\equiv 3\bmod 4$$, start by identifying the multiples of $$m$$ where the argument is $$4m-1$$. There will be three such values $$m,2m,3m$$ such that $$m+2m=3m$$, so put $$m+2m$$ in one block and $$3m$$ in the other:

$$1+2+3+4+5+6+7+8+9+10+11=1+2\color{blue}{+3}+4+5\color{blue}{+6}+7+8\color{brown}{+9}+10+11$$

The remaining terms are partitioned outside in, the same way as for a multiple of $$4$$ terms described above:

$$\color{blue}{1+11}\color{brown}{+2+10}\color{blue}{+4+8}\color{brown}{+5+7}\color{blue}{+3+6}\color{brown}{+9}$$

$$=\color{blue}{1+3+4+6+8+11}\color{brown}{+2+5+7+9+10}$$