Product of a and b should be equal to the sum of all numbers in the sequence excluding a and b

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$$