eolymp
bolt
Try our new interface for solving problems
Problems

Chain of Fools

Chain of Fools

Many of you have heard the story of Turing's bicycle: Seems the sprocket on the crank of the bicycle had a broken prong. Also his chain had one link that was bent. When the bent link on the chain came to hook up with the broken prong, the chain would fall o and Turing would stop and put the chain back on. But Turing, being who he was, could predict just when this was going to happen - meaning he would know how many pedal strokes it would be - and so would hop o his bike just before it happened and gently move the pedals by hand as the undesired coupling passed. Then he'd be merrily (we imagine) on his way. (A picture of the sprocket-chain set up is shown below.) Your job here is to calculate the number of revolutions required in such a situation as Turing's: You'll be given the number of prongs on the front sprocket, the number of links on the chain, the location of the broken prong and the location of the bent link in the chain. The top prong is at location \textbf{0}, then the next one forward on the sprocket is location \textbf{1} and so on until prong numbered \textbf{s-1}. (See the diagram. Notice that prong \textbf{s-1} is the next prong that moves to the top of the sprocket as Turing pedals.) Location of the links is similar: The link at the top of the sprocket is location 0 and so on forward until \textbf{c-1}. The chain falls o when broken prong and bent link are both at location \textbf{0}. \includegraphics{https://static.e-olymp.com/content/e2/e26dc62aa054e36667e845c865b25af6f2d088c3.jpg} \InputFile Input for each test case will be one line of the form \textbf{s c p l}, where \textbf{s} is the number of prongs on the front sprocket (\textbf{1} < \textbf{s} < \textbf{100}) , \textbf{c} is the number of links in the chain (\textbf{200} > \textbf{c} > \textbf{s}), \textbf{p} is the initial position of the broken prong, and \textbf{l} is the initial position of the bent link. The line \textbf{0 0 0 0} will follow the last line of input. Broken prong and bent link will never both start at position \textbf{0}. \OutputFile For each test case output a single one line as follows: \textbf{Case n: r m/s} if it requires \textbf{r} \textbf{m/s} revolutions to \textbf{ }first fail, or \textbf{Case n: Never} if this can never happen. Note that the denominator of the fraction will always be the number of prongs on the sprocket; the fraction will not necessarily be in lowest terms. Always print the values of \textbf{r} and \textbf{m}, even if \textbf{0}.
Time limit 1 second
Memory limit 64 MiB
Input example #1
40 71 32 23
20 40 4 24
40 71 8 33
20 40 3 17
0 0 0 0
Output example #1
Case 1: 1 8/40
Case 2: 0 16/20
Case 3: 25 32/40
Case 4: Never
Source 2011 East Central Regional Contest