ideal number gernerator

54 Views Asked by At

I was trying to solve a problem on Hackerearth.
Here: https://www.hackerearth.com/problem/algorithm/ideal-random-number-generator/
I solved this partially:https://ideone.com/pXkHwQ (passed three cases)
I am missing on some mathematical concept of probability. Can anyone help me here. I just need the concept, not the full answer.

1

There are 1 best solutions below

0
On

Hint:

Suppose for a moment that the ideal number generator generates any integer between $ A $ and $ B $ instead of real number.

Then the probability of $ X_1 + X_2 \le C $ can be found as

$ \sum_{M} P(X_1 = M) P(X_2 \le C - M) $

For a concrete example, let say A = B = 6, then the probability that $ X_1 + X_2 \le 8 $ is $ P(X_1 = 1)P(X_2 \le 7) + P(X_1 = 2)P(X_2 \le 6) + \cdots + P(X_1 = 6)P(X_2 \le 2) $

Which should be $ \frac{1}{6}(1 + 1 + \frac{5}{6} + \cdots + \frac{2}{6}) $

The challenge for this problem is the generalize this approach to real number.