#K74637. Consecutive Sum Representation

    ID: 34242 Type: Default 1000ms 256MiB

Consecutive Sum Representation

Consecutive Sum Representation

Given an integer n, your task is to determine the number of ways to express n as the sum of two or more consecutive positive integers.

More formally, you need to find the number of distinct pairs of integers \( (a, k) \) with \( a \ge 1 \) and \( k \ge 2 \) such that:

\( n = a + (a+1) + \cdots + (a+k-1) \)

If no such representation exists, output 0.

Example:

  • For \( n = 15 \), there are 3 ways: \( 1+2+3+4+5 \), \( 4+5+6 \), and \( 7+8 \).
  • For \( n = 9 \), there are 2 ways: \( 2+3+4 \) and \( 4+5 \).

inputFormat

The input consists of a single line containing an integer ( n ) ((1 \le n \le 10^9)).

outputFormat

Output a single integer representing the number of ways to express ( n ) as the sum of two or more consecutive positive integers.## sample

15
3