Prime Array
Practice
3.3 (16 votes)
Basic number theory 1
Algorithms
Number theory
Sieve
Arrays
Math
Problem
78% Success 9469 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an array \(A\) having \(N\) integers. Find the number of triplets \((i, j, k)\) such that
- \(1 \le i \lt j \lt k \le N\).
- \(A_i \times A_j \times A_k\) 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 \(A_1, A_2,\dots, A_N\).
Output format
For each test case, print the number of triplets that satisfies the given conditions in a separate line.
Constraints
\(1\le T \le 10\)
\(3 \leq N \le 10^5\)
\(1\le A_i \le 10^5\)
Sample Input
2 4 4 5 6 2 4 1 1 4 5
Sample Output
0 1
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 \times 1 \times 5 = 5\) which is prime number.
Code Editor
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Submissions
Please login to view your submissions
Similar Problems
Points:20
42 votes
Tags:
ApprovedCombinatoricsEasyMathOpenOthers
Points:20
58 votes
Tags:
AlgorithmsApprovedEasyMathOpen
Points:20
32 votes
Tags:
ApprovedCombinatoricsEasyImplementationMathOpen
Editorial
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor