Submit | All submissions | Best solutions | Back to list |
BALLSUM - Ball sum |
You have a bag filled with N balls. Each ball has a distinct number from 1 to N printed on it. All the numbers are distinct. You withdraw two balls from the bag and take their sum. You need to calculate the probability that the sum is not greater than the given number K (<= N). The answer should be displayed in the form of p/q (except when the answer is 0 or 1.)
Input
Input consists of various test cases. Each test case consist of two integer inputs, N and K. (0 <= K <= N <= 1000000000) The program stops taking input when N and K equals -1.
Output
Output the result in the form of p/q (except when the answer is 0 or 1.)
Example
Input: 3 2 100 5 10 6 -1 -1 Output: 0 2/2475 2/15
Added by: | Prateek Agarwal |
Date: | 2015-12-15 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 GOSU JS-MONKEY |
hide comments
|
||||||||
2024-02-29 09:13:03
Test your code here: https://www.udebug.com/SPOJ/BALLSUM [Sample case] 1000000000 1000000000 3 2 4 4 100 5 10 6 5218372 28732 82671 821 826713 222334 6273 2138 9919921 3231871 1000000000 999772157 -1 -1 [Accepted output] 499999999/999999999 0 1/3 2/2475 2/15 6069635/400461781059 33620/683441157 6178995361/170863389414 95141/1639344 174083061615/3280160757544 62471522744555521/124999999875000000 Simple math with gcd indeed. I can solve BALLSUM but I cannot solve https://www.spoj.com/problems/RABBIT1/. |
||||||||
2020-06-25 10:42:51
ohh.....! at last i have done it |
||||||||
2019-03-13 08:54:19
phewwww. finally AC be careful with extralarge number, u may need long long int type |
||||||||
2018-12-14 14:06:04
got it in O(1) :) easy problem needs gcd!!! |
||||||||
2018-04-25 08:48:01
Got 4 WA's and finally an AC with the same code!!! |
||||||||
2018-04-10 12:35:00
Note that K <= N. Last edit: 2018-04-22 08:11:52 |
||||||||
2018-03-15 11:08:24
getting tle |
||||||||
2018-01-11 14:55:13
for n=k=0=1 what will be the output? |
||||||||
2017-12-29 17:45:39
Very Nice problem... It consist of mathematics, also GCD. AC in one go :) |
||||||||
2017-12-27 13:01:56
O(1).............. :) |