Recipes
Time limit1sMemory limit128 MB
Multiply each recipe amount by a constant and print the result as a reduced integer or mixed fraction.
- Level
Easy2 of 10
- Topics
- Implementation, Math, Number theory
- Solved
- No attempts yet
Problem
A little-known fact about Richard Stallman is that he loves to share not only his source code, but also his recipes. Because of this, he often needs to scale a recipe up to feed a few extra programmers: he multiplies the amount of every ingredient by some constant factor. Doing this by hand has grown tedious, and the fractions involved lead to mistakes. Hungry programmers get grumpy when the food turns out badly, and they start losing focus and breaking the build. Your task is to prevent all of that by writing a program that converts recipes automatically.
Input
The first line contains the number of data sets. The data sets follow, each describing one recipe in the format below.
The first line of a recipe contains two integers and : the number of ingredients and the constant factor to multiply by. The next lines each describe one ingredient with three integers , , and , giving the amount used in the original recipe.
- is the number of whole units. For flour, means 2 cups.
- and give the fractional part. For flour, and means an extra cup.
On each ingredient line, and are separated by whitespace, while and are separated by a single slash (written as n/d). The denominator is always one of , , , , or .
Output
For each data set, print a line Data Set x: on its own, where is the data set number, starting from . On the following lines, print the scaled amount of each ingredient.
- If the result has no fractional part, print it as a single integer.
- Otherwise, print it in reduced form as
whole n/d, with the whole part separated from the fraction by a single space (the whole part may be ).
Separate consecutive data sets with a blank line.