Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

How Many Litchis?

Limits 1s, 512 MB

Tasnim comes to visit Dinajpur which is very famous for litchi production. Today, she comes to a litchi orchard and notices a strange thing. The orchard owner placed the litchis into some different sizes of buckets arranged in a row in such a way that every next bucket contains exactly one more litchi than the previous one. She also learns that the smallest bucket contains exactly M litchis and the largest one contains exactly N litchis. Tasnim is very curious to know the total number of litchis that all the buckets have. But, she is not so expert in mathematics. Moreover, she also doesn’t know how many buckets are there. So, she is asking for your help. Now, your task is to help Tasnim to determine the number of buckets and also the total number of litchis that the buckets contain.

Let me give you an example, the smallest bucket has exactly 5 litchis and the largest one has exactly 11. So, there are 5 + 6 + 7 + 8 + 9 + 10 + 11 = 56 litchis in total in 7 buckets.


There will be multiple test cases in each input file where each test case contains two integers, M and N (0 < M ≤ N ≤ 108), denoting the number of litchis in the smallest and largest bucket respectively.

Input file will be terminated when M and N both equal to zero (i.e. M is 0 and N is 0) and each input file will contain at most 100 test cases.


For each case, print the number of buckets and the total number of litchis separated by a space. Don’t forget to print a blank line for each test case.


2 5
5 11
0 0
4 14
7 56



77% Solution Ratio

edge555Earliest, 7M ago

edge555Fastest, 0.0s

Mansura_170300Lightest, 0 B

touhidurShortest, 85B


Login to submit

Related Contests