Function to count total number of pairs of elements whose sum is prime
function numPairsWithPrimeSum ( arr , n ) { let N = 2 * 1000000 ; let isPrime = sieveOfEratosthenes ( N ) ; let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { let sum = arr [ i ] + arr [ j ] ; if ( isPrime [ sum ] ) { count ++ ; } } } return count ; }