Count Consecutive Positive Integer Sums
Company: Airbnb
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
Overview: Count representations of a positive integer as one or more consecutive positive integers, including the one-term representation. Derive the arithmetic condition for each sequence length and use a square-root bound rather than testing every possible starting value.
Constraints
- n is a positive integer no greater than 10^12.
- Every term must be positive.
- Terms increase by exactly one.
- Different starts or lengths are distinct.
- Return an exact integer count.
Examples
Input: (1,)
Expected Output: 1
Explanation: One is represented only by itself.
Input: (2,)
Expected Output: 1
Explanation: Two has only its one-term representation.
Hints
- The answer equals the number of odd divisors of n.
- Remove factors of two before factoring the odd part.
- For a prime exponent e, multiply the divisor count by e + 1.