Sum of consecutive numbers

The sum of the integers from $1$ to $n$ is $\dfrac{n(n+1)}{2}$. Hence, the sum of the integers from $m+1$ to $n$ is simply $\dfrac{n(n+1)}{2}-\dfrac{m(m+1)}{2}$. So, if the sum of the integers from $m+1$ to $n$ is $N$, then

$\dfrac{n(n+1)}{2}-\dfrac{m(m+1)}{2} = N$

$(n^2+n) - (m^2+m) = 2N$

$(n-m)(n+m+1) = 2N$

Hence, $n-m$ and $n+m+1$ are complementary factors of $2N$. Clearly, $n-m$ is smaller than $n+m+1$, and since $(n+m+1)-(n-m) = 2m+1$, the factors have opposite pairity.

For any $f_1$ and $f_2$ such that $2N = f_1f_2$, $f_1 > f_2$ and $f_1$, $f_2$ have opposite parity, we can solve $n+m+1 = f_1$ and $n-m = f_2$ to get $n = \dfrac{f_1+f_2-1}{2}$ and $m = \dfrac{f_1-f_2-1}{2}$.

Therefore, the number of ways to write $N = (m+1)+(m+2)+\cdots+(n-1)+n$ is simply the number of ways to factor $2N$ into two distinct positive integers with opposite parity.

Suppose $2N = 2^{k_0+1}p_1^{k_1}p_2^{k_2}\cdots p_r^{k_r}$ where $p_1,p_2,\ldots,p_r$ are distinct odd primes. There are $(k_1+1)(k_2+1)\cdots(k_r+1)$ ways to divide the odd primes between $f_1$ and $f_2$. There are $2$ ways to give all $2$'s to one of the factors $f_1$, $f_2$. However, we need to divide by $2$ since this overcounts cases in which $f_1 < f_2$. Also, we need to subtract out the one trivial solution $n = N$ and $m = N-1$. This leaves us with $(k_1+1)(k_2+1)\cdots(k_r+1)-1$ ways to factor $2N$ into two distinct positive integers with opposite parity.

Therefore, if $N$ has prime factorization $N = 2^{k_0}p_1^{k_1}p_2^{k_2}\cdots p_r^{k_r}$, then there are $(k_1+1)(k_2+1)\cdots(k_r+1)-1$ ways to write $N$ as the sum of two or more consecutive positive integers.