Question :

Consider a  integers innum . Find and print a number outnum based on the below logic:

Using prime number range from 1 to n (both inclusive)  Find those Four number have sum is equal to given innum  .

if there is combination whose sum is equal to sum of innum  print number by space .

If there is no combination whose sum of this number  is equal to innum, print – 1

Assumption:

input number range in 1 to 10^7

Code Solution :

				
					import itertools
def prime(n):
    l=[]
    for i in range(2,n):
        if i==0 or i==1:
            continue 
        else:
            for j in range(2,int(i/2)+1):
                if i%j==0:
                    break 
            else:
                l.append(i) 
    return l

def Prime_sum(l,n):
    x=list(itertools.combinations(l,4))
    for i in x:
        if sum(i)==n:
            return i
    return -1 
n=int(input())
p=prime(n) 
print(Prime_sum(p,n))

				
			

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published.