Solution of this question in Python 3


#1

class Solution:
# @param A : integer
# @return a list of integers
def primesum(self, A):
temp=[1 for i in range(A+1)]
temp[0]=0
temp[1]=0
i=2
while i<=int(A**0.5):
if temp[i]==1:
j=2
while i*j<=A:
temp[i*j]=0
j+=1
i+=1
primes=[i for i in range(len(temp)) if temp[i]==1]
start=0
end=len(primes)-1
while start<=end:
tsum=primes[start]+primes[end]
if tsum<A:
start+=1
elif tsum>A:
end-=1
elif tsum==A:
return [primes[start],primes[end]]
return -1