# How Many Litchis?

Tasnim comes to visit Dinajpur which is very famous for litchi production. Today, she comes to a lit…

If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

• [](javascript:

# 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.

## Input

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.

## Output

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.

## Sample

Input Output
2 5 5 11 0 0 4 14 7 56

### Statistics

77%Solution Ratio

edge555Earliest, 9M ago

edge555Fastest, 0.0s

touhidurShortest, 85B

### Submit

Open IDE

CPU Limit Exceeded1m ago

### Editorial

You have to use ‘sum of interval’ formula. Iterative solution may cause TLE or CPU Limit Exceed… Read more…

### Related Contests

© 2020 Toph | Furqan Software

#### Submission 471348

# Author Problem Time Language CPU Memory
471348 Aritra15 How Many Litchis? 1m ago Python 3.7 1.0s 4.7 MB CPU Limit Exceeded

### Your Code Took Too Long to Complete Running

This usually means your submission doesn’t solve the problem efficiently enough. Please check the limits mentioned in the problem statment and the factors that are applied to the programming language you are using.

### Test Cases

# CPU Memory
1 0.0s 4.6 MB Accepted
2 0.2s 4.7 MB Accepted
3 1.0s 4.6 MB CPU Limit Exceeded
4 0.0s 0 B Skipped
5 0.0s 0 B Skipped
6 0.0s 0 B Skipped
7 0.0s 0 B Skipped
8 0.0s 0 B Skipped

### Source

solution.py 199B

Python

``````run=True
while run:
M,N=input().split()
m=int(M)
n=int(N)
if m==0 and n==0:
run=False
break
sum=0
for i in range(m,n+1):
sum=sum+i
sum2=n-m+1
print(str(sum2)+" "+str(sum))
``````

Your code has taken too long time to complete running.Because you have used for loop to solve it .You should use mathematical formula to solve it in stead of for loop.