Program-4

A semi prime number is an integer which can be expressed as the product of two prime numbers. The two primes in the product may equal each other. For example 15 = 3*5 is a semiprime number. Given an integer number N, find whether it can be expressed as a sum of two semi-primes or not (not necessarily distinct).

prime=[]
for i in range(2,100):
flag=0
for j in range(2,i):
if i%j==0:
flag=1
if flag==0:
prime.append(i)

product=[]
for i in range(0,len(prime)-1):
for j in range(i+1,len(prime)):
if i!=j:
p=prime[i]*prime[j]
product.append(p)
sum=[]
for i in range(len(product)):
for j in range(len(product)):
s=product[i]+product[j]
sum.append(s)

n=int(input("Enter the integer: "))
c=0
for i in range(len(sum)):
if sum[i]==n:
c=1
if c==1:
print("YES")
else:

print("NO")


Sample Input and Output

Enter the integer: 45
YES
Enter the integer: 46
NO

No comments:

Post a Comment