Ctrl K

Sums of Consecutive Numbers

Hard
Given a positive integer total, count the ways to write it as a sum of one or more consecutive positive integers. The number total on its own (a sum with a single term) counts as one way too.
Example 1
total=12 → 2

12 = 12 and 12 = 3 + 4 + 5: two ways.

Example 2
total=21 → 4

21 = 21 = 10 + 11 = 6 + 7 + 8 = 1 + 2 + 3 + 4 + 5 + 6.

Example 3
total=16 → 1
Constraints
  • 1 ≤ total ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPalindrome From Two Factors HardMirror Squares in a Range HardWhere Moss Species Meet HardPalindromes in Two Bases HardSplit a Tree Into Equal Parts Hard
loading Python…
Input
total=12
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 55 tests on the server, hidden ones included.