Given an arr[] of positive integers you have to count how many numbers can be represented as sum of same parity prime numbers(can be same)

**Examples:**

Input : arr[] = {1, 3, 4, 6} Output : 2 4 = 2+2, 6 = 3+3 Input : arr[] = {4, 98, 0, 36, 51} Output : 3

1. If two numbers of same parity are added then they would be always even, so all odd numbers in the array can never contribute to answer.

2. Talking about 0 and 2 both cannot be represented by sum of same parity prime numbers.

3. Rest of all numbers will contribute to the answer (Refer https://www.geeksforgeeks.org/program-for-goldbachs-conjecture-two-primes-with-given-sum/)

So, we have to just iterate over the entire array and find out number of even elements not equal to 0 and 2.

## C++

`#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to calculate count ` `int` `calculate(` `int` `* array, ` `int` `size) ` `{ ` ` ` `int` `count = 0; ` ` ` ` ` `for` `(` `int` `i = 0; i < size; i++) ` ` ` `if` `(array[i] % 2 == 0 && ` ` ` `array[i] != 0 && ` ` ` `array[i] != 2) ` ` ` `count++; ` ` ` ` ` `return` `count; ` `} ` ` ` `// Driver Code ` `int` `main() ` `{ ` ` ` `int` `a[] = { 1, 3, 4, 6 }; ` ` ` `int` `size = ` `sizeof` `(a) / ` `sizeof` `(a[0]); ` ` ` `cout << calculate(a, size); ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to Count numbers ` `// which can be represented as ` `// sum of same parity primes ` `import` `java.util.*; ` ` ` `class` `GFG ` `{ ` `// Function to calculate count ` `public` `static` `int` `calculate(` `int` `ar[], ` ` ` `int` `size) ` `{ ` ` ` `int` `count = ` `0` `; ` ` ` ` ` `for` `(` `int` `i = ` `0` `; i < size; i++) ` ` ` `if` `(ar[i] % ` `2` `== ` `0` `&& ` ` ` `ar[i] != ` `0` `&& ` ` ` `ar[i] != ` `2` `) ` ` ` `count++; ` ` ` ` ` `return` `count; ` `} ` ` ` `// Driver code ` `public` `static` `void` `main (String[] args) ` `{ ` ` ` `int` `a[] = { ` `1` `, ` `3` `, ` `4` `, ` `6` `}; ` ` ` `int` `size = a.length; ` ` ` `System.out.print(calculate(a, size)); ` `} ` `} ` ` ` `// This code is contributed ` `// by ankita_saini ` |

*chevron_right*

*filter_none*

## Python 3

`# Function to calculate count ` `def` `calculate(array, size): ` ` ` ` ` `count ` `=` `0` ` ` ` ` `for` `i ` `in` `range` `(size): ` ` ` `if` `(array[i] ` `%` `2` `=` `=` `0` `and` ` ` `array[i] !` `=` `0` `and` ` ` `array[i] !` `=` `2` `): ` ` ` `count ` `+` `=` `1` ` ` ` ` `return` `count ` ` ` `# Driver Code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` `a ` `=` `[ ` `1` `, ` `3` `, ` `4` `, ` `6` `] ` ` ` `size ` `=` `len` `(a) ` ` ` `print` `(calculate(a, size)) ` ` ` `# This code is contributed ` `# by ChitraNayal ` |

*chevron_right*

*filter_none*

## C#

`// C# program to Count numbers ` `// which can be represented as ` `// sum of same parity primes ` `using` `System; ` ` ` `class` `GFG ` `{ ` `// Function to calculate count ` `public` `static` `int` `calculate(` `int` `[]ar, ` ` ` `int` `size) ` `{ ` ` ` `int` `count = 0; ` ` ` ` ` `for` `(` `int` `i = 0; i < size; i++) ` ` ` `if` `(ar[i] % 2 == 0 && ` ` ` `ar[i] != 0 && ` ` ` `ar[i] != 2) ` ` ` `count++; ` ` ` ` ` `return` `count; ` `} ` ` ` `// Driver code ` `static` `public` `void` `Main (String []args) ` `{ ` ` ` `int` `[]a = { 1, 3, 4, 6 }; ` ` ` `int` `size = a.Length; ` ` ` `Console.WriteLine(calculate(a, size)); ` `} ` `} ` ` ` `// This code is contributed ` `// by Arnab Kundu ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// Function to calculate count ` `function` `calculate(&` `$array` `, ` `$size` `) ` `{ ` ` ` `$count` `= 0; ` ` ` ` ` `for` `(` `$i` `= 0; ` `$i` `< ` `$size` `; ` `$i` `++) ` ` ` `if` `(` `$array` `[` `$i` `] % 2 == 0 && ` ` ` `$array` `[` `$i` `] != 0 && ` ` ` `$array` `[` `$i` `] != 2) ` ` ` `$count` `++; ` ` ` ` ` `return` `$count` `; ` `} ` ` ` `// Driver Code ` `$a` `= ` `array` `(1, 3, 4, 6 ); ` `$size` `= sizeof(` `$a` `); ` `echo` `calculate(` `$a` `, ` `$size` `); ` ` ` `// This code is contributed ` `// by ChitraNayal ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

2

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Count of primes below N which can be expressed as the sum of two primes
- Count primes that can be expressed as sum of two consecutive primes and 1
- Check if all nodes of the Binary Tree can be represented as sum of two primes
- Count of ways in which N can be represented as sum of Fibonacci numbers without repetition
- Find the prime numbers which can written as sum of most consecutive primes
- Length of largest sub-array having primes strictly greater than non-primes
- Nth Term of a Fibonacci Series of Primes formed by concatenating pairs of Primes in a given range
- Count of all possible pairs of array elements with same parity
- Number of ways in which N can be represented as the sum of two positive integers
- Construct a square Matrix whose parity of diagonal sum is same as size of matrix
- Find the smallest positive number which can not be represented by given digits
- Count of primes in a given range that can be expressed as sum of perfect squares
- Check if given number can be represented as sum of two great numbers
- Check if a number can be represented as a sum of 2 triangular numbers
- Count array elements that can be represented as sum of at least two consecutive array elements
- Minimum integer that can be obtained by swapping adjacent digits of different parity
- Count numbers < = N whose difference with the count of primes upto them is > = K
- Count elements in an Array that can be represented as difference of two perfect squares
- Check if an integer can be expressed as a sum of two semi-primes
- Check whether a number can be represented by sum of two squares

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.