You are given an array \(A\) having \(N\) integers and \(Q\) queries. Each query is described by two integers \(L\) and \(R\). For each query, find the number of pairs \((i, j)\) such that \(L \leq i \lt j \leq R\) and \(A_i + A_j\) can be expressed as the sum of one or more prime numbers.
In the sum, you are allowed to use a prime number more than once.
Input format
- The first line of input contains an integer \(T\) denoting the number of test cases.
- The first line of each test case contains an integers \(N\).
- The second line of each test case contains \(N\) space-separated integers \(A_1, A_2,\dots, A_N\).
- Then \(Q\) lines follow, each containing two space-separated integers \(L\) and \(R\).
Output format
For each query, print the number of pairs that satisfies the given conditions in a separate line.
Constraints
- In the first query the pairs will be -
- \((3, 5) = A_3 + A_5 = 1 + 5 = 6\) and \(6\) can be expressed as the sum of primes \((2 + 2 + 2)\).
-
\((4, 5) = A_4 + A_5 = 0 + 5 = 5\) and \(5\) can be expressed as the sum of primes \((2 + 3)\).
-
In the second query pairs will be \((1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 5), (4, 5)\).
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
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