Given a positive integer $n$, some positive integers $x$ can be represented as follows:
$1 \le i \le j \le n$ $x = \sum_{k=i}^{j}k$
Given $n$ and $x$ determine if it can be represented as the above sum (if $\exists{i,j}$), and if so determine the $i$ and $j$ such that the sum has the smallest number of terms. (minimize $j-i$)
I am not sure how to approach this. Clearly closing the sum gives:
$x = {j^2 + j - i^2 + i \over 2}$
But I'm not sure how to check if there are integer solutions, and if there are to find the one with smallest $j-i$.