2018 ACIS REDIS - XXXII Colombian Programming Contest - ACM ICPC 18

J: Jawbreaking Candy Source file name: jawbreaking.c, jawbreaking.cpp, jawbreaking.java, or jawbreaking.py Author: Juan Camilo Corena The Advanced Cutting Machines (ACM) has developed a new product for cutting rectangular candies into shorter pieces. The width of candies has been optimized already, so this machine’s purpose is about optimizing the length of cuts. ACM is very excited about the new machine because it will solve the eternal discussion of how long candies should be for a given audience. The in-house Mathematics Department of ACM determined how the machine cuts the pieces of candy. The lengths of candy that the machine can cut are those shorter than original one L and can be represented as a fraction of the form a·L , where integers a and b have to satisfy 0 < a and 0 < b ≤ n. Here n represents a cutting b resolution for the different models of machine that will be produced; more expensive models will have higher cutting resolution. For example, assume Alice wishes to buy a piece of candy of length at least 320 units. If this piece were to be cut from a longer piece of 500 units of length and the cutting machine can only cut fractions of the candy with a denominator at most b = 3, then the following lengths of candy could be cut: 500, 500, 500, 1000, 1000, 1000, 1500, 1500, 1500, . . . 321321321 The in-house Mathematics Department predicts that, from these options, Alice would prefer the one with length 1000 because it is the smallest one that is at least 320, as she wished, and will have less calories. 3 Given L, n, and a desired length of candy to cut d, compute the shortest candy length that the machine can cut that is at least d units of length presented in the form of a reduced fraction (i.e., the numerator and denominator cannot share positive factors other than 1). Input The input consists of several test cases, one per line. Each line contains integers 0 < L < 106, 0 < n ≤ 5 000, and 0 < d ≤ L separated by a single space. The input ends with a line containing three blank-separated zeroes. The input must be read from standard input. Output For each test case, output the shortest length that can be cut by the machine and that is at least d units of length in the form of a reduced fraction. The output must be written to standard output. Sample Input 500 3 320 100 5 23 000 Sample Output 1000/3 25/1