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
hide comments
kira28:
2016-12-08 21:04:22
#elementary_school_maths
|
|
rrm_2016:
2016-11-26 21:27:40
Lol...that "/" in "p/q" made me submit one wrong solution...otherwise this is a very eazzyy problem..just high school combinatorics Last edit: 2016-11-26 21:27:58 |
|
hacker_sk:
2016-09-26 11:06:20
as written, it's simple math.. AC in one :) |
|
abhimanyu1996:
2016-08-04 10:53:40
AC in one. #CHAMP |
|
binari:
2016-08-01 22:09:33
Why my code gives wa, I think my code works correct in every status, by the way what should be written when n=0 and k=0 or n=1,k=1 (inputs like this)? |
|
cnexans:
2016-06-19 18:38:55
One of the first problems I solve... O(n) solutions won't work. Although there may be many solutions that can be expressed as a loop, you may find one that has a closed formula :) |
|
vineetpratik:
2016-06-18 17:56:08
o(n) solution won't work
|
|
Shubham Pandey:
2016-06-06 20:41:55
Author should have framed question properly , problem statement doesn't apply to n<2 |
|
candide:
2016-05-07 16:31:57
Simple formula. p/q must be an irreductible fraction. Input size probably supposes N>1 and K>0. Input has a trailing newline (can be a source of bug in Python). long long are needed. In Python 2, fractions module works but is slower than handcrafted code. Last edit: 2017-04-10 11:57:50 |
|
darkhire21:
2016-04-23 20:25:18
may be n>=2 always . |
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 |