Suppose we have an array nums. We have to check whether the sum of all prime elements in the given array is also prime or not
So, if the input is like nums = [1,2,4,5,3,3], then the output will be True as sum of all primes are (2+5+3+3) = 13 and 13 is also prime.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
MAX = 10000 sieve = [True] * MAX def generate_list_of_primes() : sieve = False sieve = False for i in range(2, MAX) : if sieve[i] : for j in range(2**i, MAX, i) : sieve[j] = False def solve(arr) : generate_list_of_primes() total = 0 for i in range(len(arr)) : if sieve[arr[i]] : total += arr[i] if sieve[total] : return True return False nums = [1,2,4,5,3,3] print(solve(nums))