BloombergOA #1
Consecutive Sum (Financial Engineer Intern)
Estimated MediumJudge-ready
Topics (AI-labelled)Bits & Math
Given num, count the distinct ways to write num as a sum of at least two consecutive positive integers.
Input
A single integer, 1≤num≤10¹².
Output
Output the number of representations.
Example 1
Input:
15
Output:
3
Example 2
Input:
2
Output:
0
Example 3
Input:
9
Output:
2
Example notes
15 has three: 1+2+3+4+5, 4+5+6, 7+8; 2 has none; 9 has two: 2+3+4, 4+5.
Editorial
Loading solution…