Given Hyobin's random arrival time in [D,E] and Yeongseon's fixed wait-walk cycle, compute the probability that Yeongseon is C or more seconds late.
Medium6MathImplementationNo attempts yetTime limit2sMemory limit512 MBHyobin lectures to friends at an algorithm club. The lectures are perfect, but Hyobin does not keep to the clock.
Yeongseon arrives at the classroom right when the lecture is supposed to start, with no idea when Hyobin will show up. To spend less time just sitting and waiting, Yeongseon uses this routine.
So Yeongseon is in the classroom from second 0 to second A, from second A+B to second 2A+B, and so on at the same spacing. Each of those intervals includes both endpoints. At every other moment Yeongseon is outside on a walk.
Hyobin does not forgive tardiness. If Hyobin is already in the classroom when Yeongseon comes back from a walk, Yeongseon counts as late. If Yeongseon reaches the classroom C or more seconds after the moment Hyobin arrived, Yeongseon cannot attend Hyobin's class.
The time at which Hyobin reaches the classroom is distributed uniformly over the real interval from D to E seconds, endpoints included. Write a program that computes the probability that Yeongseon cannot attend Hyobin's class.
The first line contains five integers A, B, C, D, E separated by spaces. (1≤A,B,C,E≤107, 0≤D≤E)
Print the probability that Yeongseon cannot attend Hyobin's class on the first line, as a reduced fraction p/q. Here p and q are integers with q≥1 and gcd(p,q)=1. Print 0/1 when the probability is 0 and 1/1 when it is 1.
If D=E, Hyobin's arrival time is fixed at second D. In that case print 1/1 when Yeongseon cannot attend, and 0/1 when Yeongseon can.
Take A=20, B=30, C=10, D=0, E=50. Hyobin arrives at some moment between second 0 and second 50. Yeongseon waits in the classroom from second 0 to second 20, walks from second 20 to second 50, and is back in the classroom at second 50. Hyobin waits only up to 10 seconds after arriving. So if Hyobin arrives between second 20 and second 40, Yeongseon returns at second 50 and cannot attend. That stretch has length 20 and the whole range has length 50, so the probability is 20/50, which as a reduced fraction is 2/5.