#P3910. Consecutive Stamp Purchase
Consecutive Stamp Purchase
Consecutive Stamp Purchase
The post office recently launched a set of commemorative stamps. There are N stamps in the set, each with a unique denomination arranged in increasing order: 1, 2, 3, …, N cents.
Xiaoming, an avid stamp collector, is very fond of this set. Unfortunately, he only has M cents at hand, which is not enough to buy the entire collection. However, he wishes to spend exactly all his money. In doing so, he insists on buying stamps whose numbers (and thus denominations) are consecutive. That is, he wants to buy all stamps from a cents to b cents where 1 ≤ a ≤ b ≤ N and the total value equals M cents.
The sum of the consecutive stamps from a to b can be expressed in LaTeX format as:
\( \frac{(a+b)(b-a+1)}{2} = M \)
Your task is to find and output all valid intervals [a, b] satisfying the conditions above.
inputFormat
The input consists of a single line containing two space-separated integers N and M, where N is the total number of stamps and M is the total amount of money that must be spent.
outputFormat
For each valid interval [a, b] that meets the requirements, output the interval in the format [a,b] (without any extra spaces). Output one interval per line in increasing order of a. If there are multiple solutions, output all of them.
sample
10 15
[1,5]
[4,6]
[7,8]
</p>