Sheep Cloning
Time limit1sMemory limit128 MB
Design a minimum-length sequence of ENTER and CLONE commands so every cloning machine's sheep count reaches its exact target capacity via prime multiplications shared across machines under a per-command size limit.
- Level
Hard8 of 10
- Topics
- Greedy, Number theory, Math, Simulation
- Solved
- No attempts yet
Problem
Sanggeun wants to increase the number of sheep using several cloning machines. Initially, each machine contains exactly one sheep.
Each cloning machine has a keyboard, and a prime number p can be entered into it. Suppose a machine currently contains K sheep and p is entered on that machine. When its clone button is pressed, the number of sheep in that machine becomes p*K.
Each machine has a maximum capacity and cannot contain more sheep than that capacity. Sanggeun wants every machine to reach its given maximum capacity exactly. Sheep cannot be removed during cloning.
Sanggeun places one assistant in front of each machine and announces two kinds of commands to all assistants.
ENTER p: tells every assistant to enter the prime numberpinto their own machine.CLONE a1, a2, ..., ak: tells the assistants in front of machinesa1, a2, ..., akto press the clone button. The machine numbers in one command must all be distinct so that no assistant presses twice in the same command. Also, oneCLONEcommand may contain at mostMnumbers.
Print a sequence of commands that maximizes the number of sheep in every machine while using the minimum possible number of commands. If several minimum-length sequences are possible, print any one of them.
Input
The first line contains the number of cloning machines N. (1 <= N <= 50)
The second line contains the maximum capacity of each machine. Each capacity is a positive integer less than 1,000,000,000.
The third line contains M, the maximum number of machine numbers that may be spoken in one CLONE command. (1 <= M <= N)
Output
Print one command per line. The number of printed commands must be minimum, and if multiple minimum command sequences satisfy the requirements, any one of them may be printed.