Function to count total number of pairs of elements whose sum is prime
def numPairsWithPrimeSum ( arr , n ) : NEW_LINE INDENT N = 2 * 1000000 NEW_LINE isPrime = sieveOfEratosthenes ( N ) NEW_LINE count = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT sum = arr [ i ] + arr [ j ] NEW_LINE if ( isPrime [ sum ] ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT DEDENT return count NEW_LINE DEDENT