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