Here's one more way to calculate this, from my answer to this question on another site:
An integer $n$ is expressible as the sum of $m$ consecutive positive integers if and only if either:
- $m$ is odd and $\frac nm$ is an integer, or
- $m$ is even and $\frac nm + \frac12$ is an integer,
and $\frac nm \ge \frac m2$ (or else some of the integers in the sum would be zero or negative).
These conditions follow from the fact that the sum of an arithmetically increasing sequence of $m$ numbers equals $m$ times the mean of the numbers.
The last condition can be rewritten as $m \le \sqrt{2n}$. Thus, it's sufficient to iterate over all integers $m$ from $1$ to $\lfloor \sqrt{2n} \rfloor$ and check whether $\frac nm + \frac m2 + \frac12$ is an integer.