Ultimate Device

Time limit10sMemory limit128 MB

Summary
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 nn kinds of circuits. The ii-th kind has a burning cycle of tit_i seconds: if a circuit with burning cycle tit_i is placed in the device, it enters its burning state at every multiple of tit_i seconds (that is, at seconds ti,2ti,3ti,…t_i, 2t_i, 3t_i, \dots).

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 33 and 55 used together. At second 33 only circuit 1 is burning, so both survive; at second 55 only circuit 2 is burning, so both survive; at second 66 only circuit 1 is burning again. Finally, at second 1515 both circuits are burning simultaneously and burn out. Three circuits with cycles 3,4,53, 4, 5 used together burn out at second 6060, while using only the first two (3,43, 4) burns out at second 1212.

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 nn circuits, the selected circuits form his device. Compute the expected lifetime of the device. If no circuit is selected, the lifetime is 00.

Input

The first line contains an integer TT (T≤100T \le 100), the number of test cases.

Each test case begins with a line containing an integer nn (1≤n≤1001 \le n \le 100), the number of circuits. The next line contains nn space-separated integers; the ii-th integer is the burning cycle tit_i (1≤ti≤5001 \le t_i \le 500) of the ii-th circuit. All burning cycles within a single test case are distinct.

Output

For each test case, print the case number, followed by (r⋅2n) mod 10007(r \cdot 2^n) \bmod 10007, where rr is the expected lifetime of the device. If r⋅2nr \cdot 2^n is not an integer, print not integer without the quotes.

Use the format Case x: y, where xx is the case number (starting from 1) and yy is the computed value.

Examples3

  1. Example 1

    Input
    2
    3
    3 4 5
    2
    2 7
    
    Expected output
    Case 1: 119
    Case 2: 23
    
  2. Example 2

    Input
    1
    1
    1
    
    Expected output
    Case 1: 1
    
  3. Example 3

    Input
    1
    1
    500
    
    Expected output
    Case 1: 500