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
|
||||||||
2015-12-26 19:13:08
Nice, logarithmic time solution .. :) |
||||||||
2015-12-23 16:43:52 [Lakshman]
@nikhilkamat2 Yes. @Shubham Dash Hint :: You need logarithmic time algorithm to solve this. |
||||||||
2015-12-23 16:37:24
Do we have to print the fractions in lowest terms? |
||||||||
2015-12-22 14:44:31 Shubham Dash
[code removed] my solution is giving TLE even in O(n)....can anyone guide me? Last edit: 2015-12-22 15:41:57 |
||||||||
2015-12-21 08:52:42 Sanchit Kumar
@prrateekk It should be mentioned that N >= 2, as we need to pick 2 balls. Last edit: 2015-12-21 08:53:13 |
||||||||
2015-12-18 04:00:29 Prakhar Dev Gupta
. Easy Problem :) Last edit: 2015-12-18 04:30:33 |
||||||||
2015-12-15 19:05:53 Prateek Agarwal
@brandon105 Changes have been made to the test cases. |
||||||||
2015-12-15 18:31:15
is the sample output correct?? |