Question: Please write a C++ programming code following those instructions A prime number is a number greater than 1 that has no positive integer divisors other

Please write a C++ programming code following those instructionsPlease write a C++ programming code following those instructions A prime numberis a number greater than 1 that has no positive integer divisors

A prime number is a number greater than 1 that has no positive integer divisors other than 1 and itself. Conversely, a composite number is any number greater than 1 that is divisible by numbers other than 1 and itself. In other words, a composite number is any number greater than 1 that is not a prime number. To help elucidate the distinction between these two types of numbers, you will write a program that accepts as input a positive integer n and outputs a list of all the prime numbers in the range [2, n] followed by a list of all the composite numbers lying in the same range. To ensure that your program always terminates within a reasonable amount of time, you will separate the prime and composite numbers using the Sieve of Eratosthenes The Sieve of Eratosthenes is an algorithm designed to efficiently find all prime numbers less than a given integer limit n. The algorithm indirectly identifies prime numbers by iteratively marking as composite the multiples of each prime found starting from the first prime number 2. The steps of the algorithm are enumerated as follows 1. Create an ordered list l of all integers in the range 2,n] 2. Initialize the first prime number p 2 3. Starting from index 2 * p, iterate over the ordered list l in increments of p and lace a mark on each number visited 4. Find the first unmarked number larger than p in the ordered list I. If no such number is found, exit the algorithm, otherwise, set p to the unmarked value. 5. If p > LVn], exit the algorithm, otherwise, return to step 3 An illustrative example of the Sieve of Eratosthenes is provided as follows [2, 3, 4, 5, 6, 7, 8, 9, 10] 1st Iteration: p = 2 (First prime number) Iterate and mark in increments of 2 [2,3,A, 5,6,7,8,9,10] 2nd Iteration: p = 3 (Next unmarked number larger than 2) Iterate and mark in increments of 3 2,3,A,5,6, 7,8,9,X 3rd Iteration 5 > |V10| so exit algorithm

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!