Goldbach's Conjecture
The goal of this program is to find all unique ways to represent a given even number as the sum of two prime numbers. A prime number is an integer greater than 11 that is evenly divisible by only itself and 11. The first few prime numbers are 22, 33, 55, 77, 1111, …. The German mathematician Christian Goldbach (1690-1764) conjectured that every even number greater than 22 can be represented by the sum of two prime numbers. (This conjecture has never been proved nor has a counterexample ever been found. As such, you may assume it is true for the cases considered in this problem.) There may be several ways to represent a given even number by the sum of primes. For example, the even number 2626 may be represented as 3+233+23, 7+197+19, or 13+1313+13.
Input
Input starts with an integer nn (1≤n≤1001≤n≤100) indicating the number of cases. The following nn lines each contain a test case of a single even number xx (4≤x≤320004≤x≤32000).
Output
For each test case xx, give the number of unique ways that xx can be represented as a sum of two primes. Then list the sums (one sum per line) in increasing order of the first addend. The first addend must always be less than or equal to the second to avoid duplicates. Print a blank line after each test case.
Goldbach’s conjecture is one of the oldest and best-known unsolved problems in number theory of mathematics. Every even integer greater than 2 can be expressed as the sum of two primes.
Steps to follow :--
Python code :--
import math
MAX = 10000
primes = []
def sieveSundaram():
marked = [False] * (int(MAX / 2) + 100)
for i in range(1, int((math.sqrt(MAX) - 1) / 2) + 1):
for j in range((i * (i + 1)) << int(MAX / 2) + 1, 2 * i + 1):
marked[j] = True
primes.append(2)
for i in range(1, int(MAX / 2) + 1):
if (marked[i] == False):
primes.append(2 * i + 1)
def findPrimes(n):
if (n <= 2 or n % 2 != 0):
print("Invalid Input")
return
i = 0
while (primes[i] <= n // 2):
diff = n - primes[i]
if diff in primes:
print(primes[i], "+", diff, "=", n)
print()
return
i += 1
sieveSundaram()
findPrimes(4)
findPrimes(38)
findPrimes(100)
Just run this code and understand it.
Thank you.
Goldbach's Conjecture The goal of this program is to find all unique ways to represent a...
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...
Use MATLAB to program the following:
9. The MATLAB built-in function primes (x) finds all the prime numbers less than x. Write a M-file function "addupprime" that will sum up all the prime numbers of an input number x. Run and show 2 test cases to demonstrate that your function file is correct.
c++ The Collatz Conjecture is a conjecture in mathematics that concerns a sequence sometimes known as hailstone numbers. Given any positive integer n, the following term, n+1 is calculated as follows: If n is even, then n+1 is defined as n/2. If n is odd, then n+1 is defined as 3n + 1 The Collatz Conjecture states that, for any value of n, the sequence will always reach 1. Once the pattern reaches 1, it repeats indefinitely (3 * 1...
python
la ab X, X Lab 7 Design and implement a Python program that uses a while loop and selection statements to print the sum of the even numbers and the sum of the odd numbers (all integers) read from the keyboard. The sequence of numbers ends with a negative number: So, all numbers considered for printing the two sums are greater than or equal to 0. The sequence may be empty. Here is a possible interaction. Enter an integer:...
Program Description: Assignment #9 will be the construction of a program that reads in a sequence of integers from standard input until 0 is read, and store them in an array (including 0). This is done using iteration (choose one of for, while, or do while loop). You may assume that there will not be more than 100 numbers. Then compute the minimum number, count odd integers, compute the sum of numbers that are larger than the first number in...
Prime Number Programing in C Note: The program is to be written using the bitwise operation. Use an integer array (not a Boolean array) and a bit length (for instance 32 bits). In this program you will write a C program to find all prime numbers less than 10,000. You should use 10,000 bits to correspond to the 10,000 integers under test. You should initially turn all bits on (off) and when a number is found that is not prime,...
Program Requirements First, find all the prime numbers between 2 and a user-inputted number from the console (inclusive). The identified prime numbers must be stored in an array . The inputted number should be between 0 and 1000 (inclusive). array is large enough to o Make sure your hold all the prim e numbers. Dynamic memory allocation is not required for this assignment, so you can have unused space in your array Make sure you can handle the cases of...
Write the code in C with all the right output please.
Problem: In this assignment you will analyze a data set of 10,000 randomly generated integers. From this data set you will display a count of the prime numbers that are greater than the average (double) of the entire data set. The user will input only a single integer value to serve as the seed for the random number generator. The use of a common seed will result in output...
Assignment #9 will be the construction of a program that reads in a sequence of integers from standard input until 0 is read, and store them in an array (including 0). This is done using iteration (choose one of for, while, or do while loop). You may assume that there will not be more than 100 numbers. Then compute the minimum number, compute the largest number among the numbers that are divisible by 2, count even numbers, and compute the...
in visual studio build a masm program that prints out the
prime numbers in a array
L1001-Sieve of Eratosthenes Please use your textbook as a reference. Goal: Use what we have learned to generate prime numbers. Prime numbers have many applications in computer science and as such, efficient ways to discover prime numbers can be very useful. Mathematicians have been intrigued by the concept for ages including the Greek mathematician, Eratosthenes of Cyrene (famous for calculating the circumference o the...