Ultimate Device
Time limit10sMemory limit128 MB
Each of n distinct cycle lengths is chosen by a fair coin; find the expected LCM of the chosen subset, output as (r * 2^n) mod 10007 or "not integer".
- Level
Hard8 of 10
- Topics
- Dynamic programming, Math, Number theory, Combinatorics
- Solved
- No attempts yet
Problem
Mr. Tomisu Ghost wants to build the ultimate device. Building it requires several kinds of circuits.
A store sells kinds of circuits. The -th kind has a burning cycle of seconds: if a circuit with burning cycle is placed in the device, it enters its burning state at every multiple of seconds (that is, at seconds ).
At any given second, if at least one circuit in the device is not in its burning state, then every circuit survives that moment. But if all circuits in the device are in their burning state at the same second, they all burn out together and the device fails. In other words, if a set of circuits is used, the device fails at the time equal to the least common multiple (LCM) of the chosen burning cycles.
For example, take two circuits with burning cycles and used together. At second only circuit 1 is burning, so both survive; at second only circuit 2 is burning, so both survive; at second only circuit 1 is burning again. Finally, at second both circuits are burning simultaneously and burn out. Three circuits with cycles used together burn out at second , while using only the first two () burns out at second .
Mr. Tomisu inspects the circuits one by one. In front of each circuit he flips a fair coin: heads means he selects that circuit, tails means he rejects it. After inspecting all circuits, the selected circuits form his device. Compute the expected lifetime of the device. If no circuit is selected, the lifetime is .
Input
The first line contains an integer (), the number of test cases.
Each test case begins with a line containing an integer (), the number of circuits. The next line contains space-separated integers; the -th integer is the burning cycle () of the -th circuit. All burning cycles within a single test case are distinct.
Output
For each test case, print the case number, followed by , where is the expected lifetime of the device. If is not an integer, print not integer without the quotes.
Use the format Case x: y, where is the case number (starting from 1) and is the computed value.