Question: 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.
 There is a method for finding all the prime numbers up

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!