Summation of Four Primes
Summation of Four Primes
Aim:- A prime number is an integer larger than 1 which is divisible by no positive integers
other than 1 and itself.
Theory:-
Euler proved in one of his classic theorems that prime numbers are infinite in number. But can
every number be expressed as a summation of four positive primes? I don’t know the answer.
May be you can help!!! I want your solution to be very efficient as I have a 386 machine at
home. But the time limit specified above is for a Pentium III 800 machine. The definition of
prime number for this problem is “A prime number is a positive number which has exactly two
distinct integer factors”. As for example 37 is prime as it has exactly two distinct integer factors
37 and 1.
Input
The input contains one integer number N (N ≤ 10000000) in every line. This is the number you
will have to express as a summation of four primes. Input is terminated by end of file.
Output
For each line of input there is one line of output, which contains four prime numbers according
to the given condition. If the number cannot be expressed as a summation of four prime numbers
print the line ‘Impossible.’ in a single line. There can be multiple solutions. Any good solution
will be accepted.
Sample Input
24
36
46
Sample Output
3 11 3 7
3 7 13 13
11 11 17 7
Examples:
Input: 24
Output: 3 11 3 7
Explanation : 3+11+3+7 = 24 and 3, 11, 7 are all prime.
Input: 46
Output: 11 11 17 7
explanation : 11+11+17+7 = 46 and 11, 7, 17 are all prime.
Conclusion:
In this problem studied that the way to express a given integer as the sum of exactly four
primes.
/*Student Name: Hitesh Raghunath Dhake Class: T.E
Roll_no: 16 Batch: T1
def Num(x):
# iterates to check
# prime or not
ab=[0]*2
for i in range(2,int(x / 2)+1):
# calls function to check
# if i and x-i is prime
# or not
if (isPrime(i) != 0 and isPrime(x - i) != 0):
ab[0] = i
ab[1] = x - i
# if two prime numbers
# are found, then return
return ab
if (n % 2 != 0):
# calls the function to get
# the other two prime numbers
# considering first two primes
# as 2 and 3 (Note 2 + 3 = 5)
ab=Num(n - 5)
# Driver Code
if __name__=='__main__':
n = 28
generate(n)
Output:-