Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There is a method for finding all the prime numbers up to n > 0 called the Sieve of Eratosthenes, which you can read about

There is a method for finding all the prime numbers up to n>0 called the Sieve of Eratosthenes, which you can read about on Wikipedia. The sieve can be modified it so that it counts the number factors of all the numbers from 1 to n by doing the following:
Make a list of the numbers from 1 to n, and set the number of factors of each to 0.
Starting at 1, add one to the number of factors of every number up to n.
Starting at 2, add one to the number of factors of every second number up to n.
Starting at 3, add one to the number of factors of every third number up to n.
Starting at 4, add one to the number of factors of every fourth number up to n.
30
...
Starting at n, add one to the number of factors of every nth number up to n.
Note, the last step only increments one number.
Write a program that reads in n, checks it is a sensible value and then prints out all the numbers from 1 to n along with how many factors it has. It should print a star beside any number that has the more factors than any smaller number (e.g.1,2,4,6 and 12 should each get a star because they are the smallest numbers to have 1,2,3,4 and 6 factors).
Hint: You can assume n1000, but you should make it easy to increase this limit.
1
P.T.O.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+what information would you need about the compact disc industry?

Answered: 1 week ago