|
||||||||||
CoprimeTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 3751 Accepted Submission(s): 1445 Problem Description There are n people standing in a line. Each of them has a unique id number. Now the Ragnarok is coming. We should choose 3 people to defend the evil. As a group, the 3 people should be able to communicate. They are able to communicate if and only if their id numbers are pairwise coprime or pairwise not coprime. In other words, if their id numbers are a, b, c, then they can communicate if and only if [(a, b) = (b, c) = (a, c) = 1] or [(a, b) ¡Ù 1 and (a, c) ¡Ù 1 and (b, c) ¡Ù 1], where (x, y) denotes the greatest common divisor of x and y. We want to know how many 3-people-groups can be chosen from the n people. Input The first line contains an integer T (T ¡Ü 5), denoting the number of the test cases. For each test case, the first line contains an integer n(3 ¡Ü n ¡Ü 105), denoting the number of people. The next line contains n distinct integers a1, a2, . . . , an(1 ¡Ü ai ¡Ü 105) separated by a single space, where ai stands for the id number of the i-th person. Output For each test case, output the answer in a line. Sample Input
Sample Output
Source | ||||||||||
|