Question: Your program should ask the user to enter a starting number (an even integer), and to enter how many numbers to test (a positive integer),

 Your program should ask the user to enter a starting number

Your program should ask the user to enter a starting number (an even integer), and to enter how many numbers to test (a positive integer), and then try to find a way to write the first number as the sum of two primes. Assuming it succeeds, proceed to the next even integer and write that as a sum of two primes, then proceed to the next, and so on, until you've done so for the requested number of numbers. If you find an even integer that can't be written in this way, print it out and call the newspapers :) You can write your program in C or C++. Submit a single PDF file containing: 1. a copy of your program's source code; and 2. its output for 500 even numbers beginning with five million (so from 5,000,000 to 5,000,998). Notes Write yourself a function that tests a single number to see if it's prime (the easiest way to see if N is prime it to try to divide N by every number from 2 to the sqrt(N). Or you can just test odd divisors, if N isn't even Rather than dividing, you can use the modulus operator (%). Remember, if a is divisible by b, then ab==0 The way you design your algorithm can have a dramatic affect on your program. Suppose you want to know if X is expressible as the sum of two odd primes: The slowest approach is to generate pairs of primes, add them, and see if they add to X. You'll do a lot of extra work, and for X around a million, your program will likely never finish A better approach is calculate the first prime(3), and then test (X-3) to see if it is prime. If it is, you're done with number X. Otherwise, generate the second prime (5) and test (X-5); if (X-5) isn't prime, then try (X-7), (X-11), and so on until one of them is prime

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!