Help me please......
The Sieve of Eratosthenes identifies all prime numbers up to a given number n as follows:
- Write down the numbers 1, 2, 3, ..., n. We will eliminate composites by marking them. Initially all numbers are unmarked.
- Mark the number 1 as special (it is neither prime nor composite).
- Set k = 1. Until k exceeds or equals the square root of n do:
- Find the first number in the list greater than k that has not been identified as composite. (The very first number so found is 2.) Call it m. Mark the numbers
2m, 3m, 4m, ...
as composite. (Thus in the first run we mark all even numbers greater than 2. In the second run we mark all multiples of 3 greater than 3.)
- m is a prime number. Put it on your list.
- Set k = m and repeat.
- Find the first number in the list greater than k that has not been identified as composite. (The very first number so found is 2.) Call it m. Mark the numbers
- Put the remaining unmarked numbers in the sequence on your list of prime numbers.
Write a function which takes as argument a maximum value. The function should return a vector of integers, each of which is prime. You should be able to determine how many prime numbers there are less than the max value.
1