Product of a and b should be equal to the sum of all numbers in the sequence excluding a and b I came across the below question in codewars. Regarding to the question, all I know is the sum of numbers ranging from 1 to n is $n(n+1)/2$. And I have no idea how to solve this question further. There were plenty of code solutions available but I wanted to understand mathematically. Can someone help me to solve this?

Given a sequence of numbers ranging from 1 to n, pick two numbers a and b 
   from that sequence such that the product of a and b should be equal to the 
   sum of all numbers in the sequence, excluding a and b

 A: The sum of all the numbers from $1$ to $n$ is $\frac 12n(n+1)$ as you say.  Then if we pick $a$ and $b$ the sum of everything else is $\frac 12n(n+1)-a-b$  We are therefore asked to find $a,b$ so that $$ab=\frac 12n(n+1)-a-b$$
We can write this as 
$$ab+a+b=\frac 12n(n+1)\\
(a+1)(b+1)=\frac 12n(n+1)+1$$
so if you can factor the number on the right into two numbers less than or equal to $n-1$ you have a solution.  For small numbers it is rare.  For example, if $n=8$ the right side is $37$, which is prime.  If $n=10$, the right is $56$ so we can factor it as $7,8$ and get $a=6,b=7$ for a solution.  $$ab=42=\frac 12\cdot 10 (10+1)-6-7=55-6-7$$
A: $${n(n+1)\over 2}-a-b=ab$$
$$ab+a+b+1={n^2+n+2\over 2}$$
$$(a+1)(b+1)={n^2+n+2\over 2}$$
So it depends on $n^2+n+2\over 2$. For instance, if $n=4$ and the expression is $11$ which is prime then there is no solution. $n=7,n=8$ are other examples with no solution.
If the expression can be factored into two numbers less than $n$ then there exists solutions. For example if $n=10$ then $a+1=7, b+1=8\implies a=6, b=7$ is a solution.
