The Sieve of Eratosthenes is the name given to an algorithm (An algorithm is a set...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
The Sieve of Eratosthenes is the name given to an algorithm (An algorithm is a set of instructions for performing some process in a finite number of steps.)for finding prime numbers (natural numbers having exactly two distinct natural number divisors, one and themselves). The sieve starts by considering all numbers greater than one as possible primes. 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ... The first number in this list, 2, must be prime but all multiples of two cannot be prime and hence can be eliminated from the list to give us 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ... The next number still in the list. 3, must also be prime since it was not eliminated when we found multiples of two. We can, however, eliminate all multiples of three to obtain 2 3 4 5 6 7 8 9 10 11 X 13 14 15 ... In the algorithm, this process continues (eliminating multiples of five, seven, and so on) until it is no longer possible to eliminate any multiples of values left in the table. The values that remain must all be primes. Write a program to implement Eratosthene's Sieve. The program should ask the user for an upper bound and should then print all the prime numbers less than or equal to that upper bound. In your program, use a boolean array to maintain a record of the numbers that are possible primes. The output should have eight values per line with each value right-justified in a field that is ten characters wide. The Sieve of Eratosthenes is the name given to an algorithm (An algorithm is a set of instructions for performing some process in a finite number of steps.)for finding prime numbers (natural numbers having exactly two distinct natural number divisors, one and themselves). The sieve starts by considering all numbers greater than one as possible primes. 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ... The first number in this list, 2, must be prime but all multiples of two cannot be prime and hence can be eliminated from the list to give us 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ... The next number still in the list. 3, must also be prime since it was not eliminated when we found multiples of two. We can, however, eliminate all multiples of three to obtain 2 3 4 5 6 7 8 9 10 11 X 13 14 15 ... In the algorithm, this process continues (eliminating multiples of five, seven, and so on) until it is no longer possible to eliminate any multiples of values left in the table. The values that remain must all be primes. Write a program to implement Eratosthene's Sieve. The program should ask the user for an upper bound and should then print all the prime numbers less than or equal to that upper bound. In your program, use a boolean array to maintain a record of the numbers that are possible primes. The output should have eight values per line with each value right-justified in a field that is ten characters wide. The Sieve of Eratosthenes is the name given to an algorithm (An algorithm is a set of instructions for performing some process in a finite number of steps.)for finding prime numbers (natural numbers having exactly two distinct natural number divisors, one and themselves). The sieve starts by considering all numbers greater than one as possible primes. 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ... The first number in this list, 2, must be prime but all multiples of two cannot be prime and hence can be eliminated from the list to give us 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ... The next number still in the list. 3, must also be prime since it was not eliminated when we found multiples of two. We can, however, eliminate all multiples of three to obtain 2 3 4 5 6 7 8 9 10 11 X 13 14 15 ... In the algorithm, this process continues (eliminating multiples of five, seven, and so on) until it is no longer possible to eliminate any multiples of values left in the table. The values that remain must all be primes. Write a program to implement Eratosthene's Sieve. The program should ask the user for an upper bound and should then print all the prime numbers less than or equal to that upper bound. In your program, use a boolean array to maintain a record of the numbers that are possible primes. The output should have eight values per line with each value right-justified in a field that is ten characters wide.
Expert Answer:
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date:
Students also viewed these programming questions
-
(yzdx+xzdy + xydz) is equal to where C is intersection of x + y +2=1 and x = 1 - 0 none
-
The material used in making parts affects not only how long the part lasts but also how difficult it is to repair. The following measurements are for screw torque removal for a specific screw after...
-
Convert the ERD below into a Relational Model (Schema List of tables). Specify the Primary and Foreign Keys clearly. id ROLE type id IS A address EMPLOYEE medical details lype name EVIDENCE name...
-
Suppose the following table reflects the total satisfaction (utility) derived from eating pizza: (a) What is the marginal utility of each pizza? (b) When does marginal utility first diminish? (c)...
-
Find the function value. Round to four decimal places. cos 4
-
In a contract dispute between a US company and a Canadian company, the contract itself referred to provisions of the Uniform Commercial Code. Do these references alone preempt the contract from being...
-
Dr. Roger Jones is a successful dentist but he is experiencing recurring financial difficulties. For example, Dr. Jones owns his office building, which he leased to the professional corporation that...
-
ces Direct labor-hours Machine-hours Fixed manufacturing overhead cost Variable manufacturing overhead per machine-hour Variable manufacturing overhead per direct labor-hour 35,000 Department Molding...
-
You are the brand manager for your favorite brand of clothing, food, vehicle, or other consumer product. Write a one-page branding statement summarizing your brand for your company's VP of Marketing....
-
Carrie is one of the "cool kids" and enjoys the social standing and reputation she gets by being part of this in-group, but she doesn't have many close relationships among the "cool kids." What type...
-
A company is facing a pending lawsuit with a potential liability of $200,000. The probability of losing the lawsuit is estimated at 60%. How should the company record this contingent liability?
-
In a Double Sideband Large Carrier (DSB-LC) modulation scheme, a modulating signal Sm(t) = 3 cos(200t) is used to modulate a carrier signal s(t) = 4 cos(410). The time domain mathematical expression...
-
Problem 1 Consider the following LP and the optimal tableau below. B.V. Z I2 I6 max 5x1 +4.5x2 + 6x3 s.t. 6x1 x1 +5x2 +8x3 60 10x1 +20x2 + 10x3 <150 x1 x1 x2 0 0 0 1 0 F1: I2, I3, I3 I5 x6 RHS 4/7...
-
How do the concepts of social capital and social networks contribute to our understanding of social cohesion, collective action, and the diffusion of information and resources within communities?
-
(a) Say you are given two datapoints (7,31) = (2,7) and (x2, 32) = (3,11). You wish to fit a polynomial model to this dataset. What is the optimal degree 0 polynomial fit to this data? Show all work....
-
The Smiths can afford a maximum mortgage payment of $1250 per month. The current interest rate is 5.2% compounded semiannually. What is the maximum mortgage loan they can afford if the amortization...
-
Is the modified 5-question approach to ethical decision making superior to the modified moral standards or modified Past in approach?
-
Compare the use of synchronization vis--vis ReentrantLock for controlling access to shared objects.
-
Write an application that plays guess the number as follows: Your program chooses the number to be guessed by selecting a random integer in the range 1 to 1000. The application displays the prompt...
-
Using the techniques create an app that continuously displays Boxes, Cylinders and Spheres on a Pane with random sizes, locations and diffuse colors. For each three-dimensional shape, create an...
-
Data from the last nine decades for the broad U.S. equity market yield the following statistics: average excess return, 8.3%; standard deviation, 20.1%. a. To the extent that these averages...
-
Suppose that the risk premium on the market portfolio is estimated at 8% with a standard deviation of 22%. What is the risk premium on a portfolio invested 25% in Toyota and 75% in Ford if they have...
-
Stock XYZ has an expected return of 12% and risk of = 1. Stock ABC has expected return of 13% and = 1.5. The markets expected return is 11%, and rf = 5%. a. According to the CAPM, which stock is a...
Study smarter with the SolutionInn App