How Many Litchis?


This is a companion discussion topic for the original entry at https://toph.co/p/how-many-litchis

Toph

  • [![|20x20](data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjUxMnB0IiB2aWV3Qm94PSIwIDAgNTEyIDUxMiIgd2lkdGg9IjUxMnB0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0yNTYgNTEyYy02OC4zNzkgMC0xMzIuNjY4LTI2LjYyOS0xODEuMDItNzQuOThDMjYuNjMgMzg4LjY2OCAwIDMyNC4zNzkgMCAyNTZTMjYuNjI5IDEyMy4zMzIgNzQuOTggNzQuOThDMTIzLjMzMiAyNi42MyAxODcuNjIxIDAgMjU2IDBzMTMyLjY2OCAyNi42MjkgMTgxLjAyIDc0Ljk4QzQ4NS4zNyAxMjMuMzMyIDUxMiAxODcuNjIxIDUxMiAyNTZzLTI2LjYyOSAxMzIuNjY4LTc0Ljk4IDE4MS4wMkMzODguNjY4IDQ4NS4zNyAzMjQuMzc5IDUxMiAyNTYgNTEyem0wLTQ3MkMxMzYuODk4IDQwIDQwIDEzNi44OTggNDAgMjU2czk2Ljg5OCAyMTYgMjE2IDIxNiAyMTYtOTYuODk4IDIxNi0yMTZTMzc1LjEwMiA0MCAyNTYgNDB6bTExMCAxOTUuOThIMTQ2djQwaDIyMHptMC03OS45OEgxNDZ2NDBoMjIwem0wIDE2MEgxNDZ2NDBoMjIwem0wIDAiLz48L3N2Zz4=)](javascript::wink:
  • [Aritra15's Avatar](javascript::wink:

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

Discussion

Statistics

77%Solution Ratio

edge555Earliest, 9M ago

edge555Fastest, 0.0s

Mansura_170300Lightest, 0 B

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

BRAC University Intra Girls’ Programming Contest Summer 2019 (Replay)Ended 9M ago

Privacy Policy Terms of Service

© 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

Download

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.