Geeksforgeeks

Error

×

Given a number **N**, find if **N **can be expressed as **a + b ** such that **a** and **b** are prime.

**Note: **If [a, b] is one solution with a <= b, and [c, d] is another solution with c <= d, and a < c then [a, b] is considered as our answer.

**Example 1:**

Input:N =8Output:3 5Explanation:3 and 5 are both prime and they add up to 8.

**Example 2:**

Input:N =3Output:-1 -1Explanation:There are no solutions to the number 3.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **getPrimes()** which takes an integer **n** as input and **returns** (a,b) as an array of size 2.

**Note: **If no value of (a,b) satisfy the condition return (-1,-1) as an array of size 2.

**Expected Time Complexity:** O(N*loglog(N))

**Expected Auxiliary Space:** O(N)

**Constraints:**

3 <= N <= 10^{6}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Sum Of Prime

...