Drawing balls without replacement

An urn holds red and blue balls. Draw several without putting them back, so each draw changes the next.

What to build

A program that prints the chance that every ball drawn is red, and the chance of at least one blue.

Requirements

  • Print P(all red) = X and P(at least one blue) = Y as reduced fractions (0 or 1 when they are).

Input

One line: r (red balls), b (blue balls) and k (balls drawn).

Output

Two lines.

Constraints

0 ≤ r, b ≤ 50; 1 ≤ k ≤ r + b.

Example

Input:

3 2 2

Output:

P(all red) = 3/10
P(at least one blue) = 7/10

Why it works

Each draw is conditional on the earlier ones, so the general multiplication rule multiplies shrinking fractions, which equals choosing k of the r red balls out of all ways to choose k balls.

Examples

Example 1 · Input
3 2 2
Expected output
P(all red) = 3/10
P(at least one blue) = 7/10
Example 2 · Input
4 4 1
Expected output
P(all red) = 1/2
P(at least one blue) = 1/2

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

All k draws are red: multiply r/(r+b), then (r−1)/(r+b−1), and so on, or use C(r, k) ÷ C(r + b, k).

Hint 2

"At least one blue" is the complement of "all red".

Solution

Show one correct solution (try it yourself first)
from fractions import Fraction
from math import comb

r, b, k = map(int, input().split())
p = Fraction(comb(r, k), comb(r + b, k))
print("P(all red) =", p)
print("P(at least one blue) =", 1 - p)

Lesson: Conditional probability →