Consecutive Sums
InterviewTime limit1sMemory limit64 MB
Print every run of two or more consecutive positive integers that sums to N, ordered by starting value.
- Level
Medium4 of 10
- Topics
- Math, Number theory
- Solved
- No attempts yet
Problem
Find every way to write a positive integer as a sum of two or more consecutive positive integers.
For example, has two such sums: and .
Input
The first line contains the positive integer ().
Output
For each run of consecutive positive integers whose sum is , print the first addend and the last addend on one line, separated by a space.
Print the runs in increasing order of the first addend. Every given in the input has at least one such run.
Hint
The sum of terms starting at equals .