#C839. Consecutive Sum Representation
Consecutive Sum Representation
Consecutive Sum Representation
Given a positive integer n
, determine the number of ways to represent n
as a sum of consecutive positive integers. In other words, find the number of sequences of consecutive positive integers whose sum equals n
.
Any sequence of k
consecutive positive integers starting with a
can be written as:
\(n = a + (a+1) + \cdots + (a+k-1) = k \cdot a + \frac{k(k-1)}{2}\)
Your task is to compute the number of such representations. Note that the representation with a single number (i.e. n
itself) is also counted.
inputFormat
The input consists of a single positive integer n
read from the standard input.
outputFormat
Output a single integer representing the number of ways to write n
as a sum of one or more consecutive positive integers. Print the result to the standard output.
15
4