Betrayal
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
...
— Marichka, do you see the stars?
Zenyk
When the sun sets below the horizon and night falls, Plast members light a campfire, sit around it, and begin doing their favorite things: singing songs, telling each other interesting and scary stories, sharing experiences, studying constellations in the sky. When all the songs have been sung and all the stories told, the Plast members, tired, disperse to their tents to rest and prepare their young bodies for the next event-filled day.
But this time everything is not as simple as the book says. One tent has somehow disappeared. Noticing the loss, all the Plast members rushed in panic in different directions. "Where is my guitar??!!", — shouted one. "Where are we going to sleep??!!" — shouted others. The disappearance of the tent clearly undermined the morale of the Plast detachment. They were not ready for such blows of fate.
However, there were two daredevils in the detachment who could not accept this cruel fate and decided to take matters into their own hands. Their names were Zenyk and Marichka. First of all, they found all their fellow Plast members who had scattered around the forest in panic and gathered them around the campfire. The next task facing Zenyk and Marichka was to determine who would sleep where that night. Calculating the number of sleeping spots taking into account the loss, Zenyk and Marichka concluded that there wouldn’t be enough places for everyone, and some would have to spend this night under the open sky.
In order to boost the morale of their comrades and make the process of choosing the lucky ones who will sleep in tents as fair as possible, Zenyk and Marichka came up with the following game. Three Plast members play: two hosts (Zenyk and Marichka) and a player. The game begins with the player writing any natural number on a sheet of paper. After that, each of the hosts names one natural number. Zenyk names a number in the range from \(a\) to \(b\), and Marichka names a number in the range from \(c\) to \(d\). Then the player shows the number they wrote on the card. If the product of the numbers named by the hosts is equal to the number written on the card, the player wins. Otherwise, they lose.
Zenyk and Marichka are going to play this game with each of their comrades. The Plast members who win will go to sleep in the remaining tents. The rest will spend the night under the open sky.
Before the game starts, Zenyk and Marichka have doubts — will there be enough room in the tents for all the winners? For each of their friends, Zenyk and Marichka know exactly what number she or he will write on the card during the game. Your task is to find the winning probability for each Plast member.
Input
The first line specifies four natural numbers \(a\), \(b\), \(c\), and \(d\) — the boundaries of Zenyk’s and Marichka’s ranges, respectively.
The second line specifies one natural number \(n\) — the number of Plast members going to play the game.
The next \(n\) lines each specify one natural number \(a_i\) — the number that the \(i\)-th participant will write.
Output
Output \(n\) lines. The \(i\)-th line should contain the winning probability of the \(i\)-th player. All probabilities must be output as a fraction \(\frac{p}{q}\), where \(p\) and \(q\) are non-negative integers.
The testing system will accept the answer to a test if the values of all probabilities are equal to the reference values, and also for each fraction \(\frac{p}{q}\) the following conditions are met: \(0 \le p \le 10^{18}, 1 \le q \le 10^{18}\).
Constraints
\(20\%\) of tests: \(n = 1, 1 \le a, b, c, d \le 10\).
\(30\%\) of tests: \(n \le 100, 1 \le a, b, c, d \le 10^3\).
\(50\%\) of tests: \(n \le 10^3, 1 \le a, b, c, d \le 10^9\).
For all tests, the constraints are satisfied: \(a < b\), \(c < d\), \(1 \le n\), \(1 \le a_i \le 10^9\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 1 3 4 7 3 12 4 47 | 1/6 1/12 0/1 |
Notes
If Zenyk names a number from 1 to 3, Marichka names a number from 4 to 7, and a participant writes the number 12 on the card, then the winning probability will be \(\frac{2}{12}\): a total of different combinations Zenyk and Marichka can name is \((3-1+1) \cdot (7-4+1)=12\), and the winning ones for the participant are only two: Zenyk names 2 and Marichka names 6: \(2 \cdot 6=12\); or Zenyk names 3 and Marichka names 4: \(3 \cdot 4=12\). Therefore, the winning probability is the ratio of these two numbers, i.e., \(\frac{2}{12}\).
A correct output for the sample input would also be:
1/6
4/36
0/9.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|