Under construction

Still being built. Things may change

Determinant of the GCD Matrix

Time limit1sMemory limit128 MB

Summary
Given a divisor-closed set of numbers, compute the determinant of the pairwise-gcd matrix modulo 1e9+7 using Smith's theorem via Euler's totient function.
Level

Medium6 of 10

Topics
Number theory, Math, Combinatorics
Solved
No attempts yet

Problem

A set S={x1,x2,…,xn}S = \{x_1, x_2, \ldots, x_n\} is closed under divisors if, for every xi∈Sx_i \in S, every divisor dd of xix_i also satisfies d∈Sd \in S.

From a divisor-closed set SS, build the greatest common divisor matrix (S)=(sij)(S) = (s_{ij}) where sij=gcd⁡(xi,xj)s_{ij} = \gcd(x_i, x_j). Write a program that computes the determinant of this matrix.

Dn=∣gcd⁡(x1,x1)gcd⁡(x1,x2)⋯gcd⁡(x1,xn)gcd⁡(x2,x1)gcd⁡(x2,x2)⋯gcd⁡(x2,xn)⋮⋮⋱⋮gcd⁡(xn,x1)gcd⁡(xn,x2)⋯gcd⁡(xn,xn)∣D_n = \begin{vmatrix} \gcd(x_1,x_1) & \gcd(x_1,x_2) & \cdots & \gcd(x_1,x_n) \\ \gcd(x_2,x_1) & \gcd(x_2,x_2) & \cdots & \gcd(x_2,x_n) \\ \vdots & \vdots & \ddots & \vdots \\ \gcd(x_n,x_1) & \gcd(x_n,x_2) & \cdots & \gcd(x_n,x_n) \end{vmatrix}

Input

The first line contains the number of test cases TT. For each test case, the first line contains the number of elements nn (0<n<10000 < n < 1000) of the set SS. The next line contains the elements x1,x2,…,xnx_1, x_2, \ldots, x_n (0<xi<2×1090 < x_i < 2 \times 10^9, and each xix_i is an integer).

Output

For each test case, print the determinant of the greatest common divisor matrix of the given set SS modulo 1,000,000,0071{,}000{,}000{,}007.

Examples1

  1. Example 1

    Input
    3
    2
    1 2
    3
    1 3 9
    4
    1 2 3 6
    
    Expected output
    1
    12
    4