Question

Python language:Given n an even positive integer (greater than or equals to the number 4) proposed...

Python language:Given n an even positive integer (greater than or equals to the number 4) proposed by the user, the algorithms prints two prime numbers p and q such
that the equality relation p + q = n is satisfied

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

#here I have taken 1 as an prime if not needed remove it
prime = [1, 2, 3]

def isPrime(n) :
#to reduce time complexity
if (n % 2 == 0 or n % 3 == 0) :
return False

i = 5
#loop to identiy whether number is prime or not
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6

return True

#get user input
evenNumber = int(input("Enter an even number >= 4 : "))

#generating prime number list
for i in range(5, evenNumber + 1):
if isPrime(i):
prime.append(i)
  
  
for x in range (0, len(prime)):
for y in range (x+1, len(prime)):
#equality condition p+q=n(evenNumber)
if(evenNumber == prime[x]+prime[y]):
print("p = "+str(prime[x])+" & q = "+str(prime[y]))
  

Output:

Enter an even number >= 4 : 24                                                                                                 

p = 1 & q = 23                                                                                                                 

p = 5 & q = 19                                                                                                                 

p = 7 & q = 17                                                                                                                 

p = 11 & q = 13

Add a comment
Know the answer?
Add Answer to:
Python language:Given n an even positive integer (greater than or equals to the number 4) proposed...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For Python: A prime number is defined as an integer greater than 1 that has no...

    For Python: A prime number is defined as an integer greater than 1 that has no positive divisors other than 1 and itself. Write a program that prompts the user for an integer > 1. Validate the value is > 1 (if not, ask for another). Use a loop to determine if the number is prime or not. Issue an appropriate message. [complete this part before proceeding]. Add a loop that continues to ask the user if they would like...

  • A positive integer greater than 1 is said to be prime if it has no divisors...

    A positive integer greater than 1 is said to be prime if it has no divisors other than 1 and itself. A positive integer greater than 1 is composite if it is not prime. Write a program that defines two functions is_prime() and list_primes(). is_prime() will determine if a number is prime. list_primes() will list all the prime numbers below itself other than 1. For example, the first five prime numbers are: 2, 3, 5, 7 and 11." THE PROGRAM...

  • Using Python: A Prime number is an integer greater than 1 that cannot be formed by...

    Using Python: A Prime number is an integer greater than 1 that cannot be formed by multiplying two smaller integer other than 1 and itself. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 × 1. In this question you will write a program that takes a sequence of integers from the user and display all the prime numbers contained in that sequence. We will separate this question in...

  • A Prime Number is an integer which is greater than one, and whose only factors are...

    A Prime Number is an integer which is greater than one, and whose only factors are 1 and itself. Numbers that have more than two factors are composite numbers. The first few prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23 and 29. The number 1 is not a prime number. Write a well-documented, Python program - the main program, that accepts both a lower and upper integer from user entries. Construct a function, isPrime(n), that takes...

  • matlab The Goldbach Conjecture asserts that every even integer greater than 2 can be expressed as...

    matlab The Goldbach Conjecture asserts that every even integer greater than 2 can be expressed as the sum of two prime numbers. Write a program that will first generate a random even number on the interval [4, 100], and print its all possible pairs of prime numbers whose sum makes this integer. For example, if n is 50, here are 4 possible pairs: 3 and 47, 7 and 43, 13 and 37, and 19 and 31. The order of the...

  • Using python Write a Python function called sgm that requests a positive integer n and returns...

    Using python Write a Python function called sgm that requests a positive integer n and returns the series geometric mean of the numbers 1,2,3, . . . n. For example sgm(5) = (5 x 4 x 3 x 2 x 1)1/5 = (120) 1/5 = 2.605 . Write the program so that a user is requested for a positive integer and program prints the series geometric mean of the integer. Example execution: Enter number: 5 series geometric mean of 5...

  • A perfect number is a positive integer that equals the sum of all of its divisors...

    A perfect number is a positive integer that equals the sum of all of its divisors (including the divisor 1 but excluding the number itself). For example 6, 28 and 496 are perfect numbers because 6=1+2+3 28 1 + 2 + 4 + 7 + 14 496 1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 + 248 Write a program to read a positive integer value, N, and find the smallest perfect number...

  • Write a program that reads a positive integer N, where N is greater than 1 and...

    Write a program that reads a positive integer N, where N is greater than 1 and prints the value of the floating-point value SUM where SUM is the results of the following series. SUM = 1/1! + 2/2! + 3/3! + 4/4! + ... N/N! Note that your program should print the message “Sorry, bad N”” if N is <=1, and keep reading user input until the user enters a valid value for N. Also, note that all division operations...

  • Prime numbers are the building blocks of all integers greater than 1. Any integer n >...

    Prime numbers are the building blocks of all integers greater than 1. Any integer n > 1 can be written as a unique product of primes i.e. n = p1 × p2 × ... × pm. Here, pi are primes such that p1 ≤ p2 ≤ ... ≤ pm. Take, for example, the number 18. It can be written as 18 = 2 × 3 × 3. 1. Write a Python function prime divisors(n) which accept an integer n and...

  • Write a Python function isPrime(number) that determines if the integer argument number is prime or not....

    Write a Python function isPrime(number) that determines if the integer argument number is prime or not. The function will return a boolean True or False. Next, write a function HowManyPrimes(P), that takes an integer P as argument and returns the number of prime numbers whose value is less than P. And then write a function HighestPrime(K) that takes integer K as an argument and returns the highest prime that is less than or equal to K. USE THE WHILE LOOP...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT