Prime Array

3.3

16 votes
Basic Number Theory-1, Algorithms, Number Theory, Sieve, Arrays, Math
Problem

 You are given an array A having N integers. Find the number of triplets (i,j,k) such that 

  • 1i<j<kN.
  • Ai×Aj×Ak is Prime number.

Input format

  • The first line of input contains an integer T denoting the number of test cases. The description of each test case is as follows:
  • The first line of each test case contains an integers N.
  • The second line of each test case contains N integers A1,A2,,AN.

Output format

For each test case, print the number of triplets that satisfies the given conditions in a separate line.

Constraints

1T103N1051Ai105

 

Sample Input
2
4
4 5 6 2
4
1 1 4 5
Sample Output
0
1
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation
  • In the first test case there are no tuples that satisfy the given coditions.
  • In the second test case the tuples will be (1,2,4) as 1×1×5=5 which is prime number.
Editor Image

?