← Back to Problems
Rejection Sampling
Easy standard Simulation & Monte Carlo
Time limit: 1 s per test  ·  Memory: 256 MB

You want to sample from the Beta distribution with parameters a and b, whose density on [0, 1] is

f(x) = x^(a-1) (1-x)^(b-1) / B(a, b)

where B is the Beta function. Your proposal distribution is the uniform density g(x) = 1 on [0, 1].

Rejection sampling requires an envelope constant M with f(x) <= M g(x) for all x. Compute the smallest valid M, and the acceptance rate of the resulting sampler: the probability that a proposed draw is accepted.

Input

One line with the two real numbers a and b, each with at most 4 digits after the decimal point.

Output

Two real numbers: the smallest valid M and the acceptance rate, each with relative error at most 1e-9.

Constraints

1 <= a, b <= 100

Scoring

This is a standard problem: a submission scores full points if it produces the correct output for every test case, and zero otherwise.

Numeric answers are accepted if they are within a relative tolerance of 1e-09 of the expected value.

Examples

input
2 2
output
1.5 0.6666666666666666
input
1 1
output
1.0 1.0
Python 3.13 i Execution environment Isolated microVM · 1 vCPU · no internet access Time and memory limits are set per problem Available packages numpy 2.5.0scipy 1.18.0pandas 3.0.0scikit-learn 1.9.0statsmodels 0.15.0cvxpy 1.9.2