Below code is for Given an even number (greater than 2), return two prime numbers whose sum will be equal to the given number my task to reach the lowest time complexity I tried it differently, but I cannot reach the lowest time complexity - please help, and I am running it on an online compiler.
class Solution:
def primesum(self, A):
# write your method here
n = A
return self.findPrimePair(A)
def findPrimePair(self,n):
isPrime = [0] * (n+1)
isPrime = [True for i in range(n + 1)]
self.SieveOfEratosthenes(n, isPrime)
for i in range(0,n):
if (isPrime[i] and isPrime[n - i]):
return i,n-i
return 0,0
def SieveOfEratosthenes(self,n, isPrime):
isPrime[0] = isPrime[1] = False
p=2
while(p*p <= n):
if (isPrime[p] == True):
i = p*p
while(i <= n):
isPrime[i] = False
i += p
p += 1