#C8354. Consecutive Sum Ways

    ID: 52327 Type: Default 1000ms 256MiB

Consecutive Sum Ways

Consecutive Sum Ways

Given a positive integer \(N\), your task is to determine the number of ways to express \(N\) as a sum of consecutive positive integers.

This can be written in a mathematical form as: \(N = a + (a+1) + (a+2) + \cdots + (a+k)\), where \(a\) is a positive integer and \(k\) is a non-negative integer. For example, when \(N = 15\), the consecutive sums are:

  • \(15\) (a single number)
  • \(7 + 8\)
  • \(4 + 5 + 6\)
  • \(1 + 2 + 3 + 4 + 5\)

Thus, there are 4 ways to represent 15 as a sum of consecutive positive integers.

inputFormat

The input is provided via standard input as a single integer (N) ((1 \leq N \leq 10^9)).

outputFormat

Output a single integer to standard output which is the number of ways to express (N) as a sum of consecutive positive integers.## sample

15
4