← 返回 airbnb 的题目列表Consecutive Numbers Sum
类型:online_judge
Given a positive integer n, return the number of ways to express n as a sum of one or more consecutive positive integers.
Formally, count pairs (start, length) such that:
start >= 1
length >= 1
n = start + (start + 1) + ... + (start + length - 1)
Pairs with different start or length are distinct.
Input format
n
Output format
The number of valid representations
Constraints
1 <= n <= 10^9
Example 1
Input: 5
Output: 2
Explanation: 5 = 5 and 5 = 2 + 3.
Example 2
Input: 15
Output: 4
Explanation: 15 = 15, 15 = 7 + 8, 15 = 4 + 5 + 6, and 15 = 1 + 2 + 3 + 4 + 5.
Example
Input
1
Output
1