Coprime 6tuples

All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
There are N integers X_{1}, X_{2}, ..., X_{N}.
Let's define Y_{i,j} = X_{i} × X_{j} mod 359999.
How many integer 6tuples (a, b, c, d, e, f) are there such that:
 1 ≤ a, b, c, d, e, f ≤ N
 gcd(Y_{a, b}, Y_{c, d}, Y_{e, f}) = 1
We define gcd(0, 0) = 0.
Input
The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N.
The second line contains N integers separated by single spaces: X_{1}, X_{2}, ..., X_{N}.
Output
For each test case, output a single line containing the answer. Since the answer can be very large, only output it modulo 10^{9} + 7.
Constraints
 1 ≤ T ≤ 3
 1 ≤ X_{i} ≤ 10^{6}
Subtasks
Subtask #1 (47 points): 1 ≤ N ≤ 10^{3}
 1 ≤ N ≤ 10^{6}
 The sum of the Ns is ≤ 10^{6}
Example
Input: 1 3 300 3000 30000 Output: 234
Author:  kevinsogo 
Tester:  iscsi 
Editorial  https://discuss.codechef.com/problems/TUPLES 
Tags  fft hard jan17 kevinsogo mobius_function numbertheory primitiveroot 
Date Added:  8122016 
Time Limit:  6 sec 
Source Limit:  50000 Bytes 
Languages:  ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.9.2, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYPY, PYTH, PYTH 3.4, RUBY, SCALA, SCM chicken, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions