0% found this document useful (0 votes)
124 views

Summation of Four Primes

The document describes an experiment to express a given integer as the sum of exactly four prime numbers, where a prime number is defined as a positive number with exactly two distinct factors. It provides sample input/output showing how different integers can be written as the sum of four primes or indicating if it is impossible. The conclusion states that this problem studies how to express a given integer as the sum of four primes.

Uploaded by

Harsh Dhake
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
124 views

Summation of Four Primes

The document describes an experiment to express a given integer as the sum of exactly four prime numbers, where a prime number is defined as a positive number with exactly two distinct factors. It provides sample input/output showing how different integers can be written as the sum of four primes or indicating if it is impossible. The conclusion states that this problem studies how to express a given integer as the sum of four primes.

Uploaded by

Harsh Dhake
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Khandesh College Education Society’s

College of Engineering & Information Technology, Jalgaon


Department of Computer Engineering
PRN No.: 21510620171124510019 Roll No: 16 Date of Exp:
Class: TE Comp. Sign of Staff Member:
=================================================================
EXPERIMENT NO.2
Title:- 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

Program Name:- Summation of Four Primes

# Python program to express


# n as sum of 4 primes.
import math;
# funcion to check if a
# number is prime or not
def isPrime(x):
# does square root
# of the number
s = int(math.sqrt(x))

# traverse from 2 to sqrt(n)


for i in range(2,s+1):
# if any divisor found
# then non prime
if (x % i == 0):
return 0
# if no divisor is found
# then it is a prime
return 1

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

# function to generate 4 prime


# numbers adding upto n
def generate(n):
# if n<=7 then 4 numbers cannot
# sum to get that number
if(n <= 7):
print("Impossible to form")

# if it is not even then 2 and


# 3 are first two of sequence

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)

# print 2 and 3 as the firsts


# two prime and a and b as the
# last two.
print("2 3",ab[0],ab[1])

# if it is even then 2 and 2 are


# first two of sequence
else:
# calls the function to get
# the other two prime numbers
# considering first two primes
# as 2 and 2 (Note 2 + 2 = 4)
ab=Num(n - 4)
# print 2 and 2 as the firsts
# two prime and a and b as the
# last two.
print("2 2",ab[0],ab[1])

# Driver Code
if __name__=='__main__':
n = 28
generate(n)
Output:-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy