Question: Write R code to return a vector of prime numbers within range from 0 to 1 0 0 0 The sieve works by marking the

Write R code to return a vector of prime numbers within range from 0 to 1000 The sieve works by marking the composite numbers- filtering them out. What is left on top are the prime numbers. Steps: * A prime number has only two factors: 1 and itself. A composite number has more than two factors. The number 1 is neither prime nor composite - because it has only one factor (1)- so we remove 1* Now we move on to number 2. We know that any of the multiples of 2 except 2 cannot be prime- because one of their factors is 2(in addition to 1 and itself). So we move through multiples of 2 and mark them as composites.* Now we move to number 3- If 3 was a factor of any of the numbers seen so far- it would have been cancelled. But it is not so the only factors of 3 are 3 and 1- and hence it is prime. Therefore if we reach any number and it has not been cancelled it has to be prime. So we mark three as prime. We move through 3 and cancel all its multiples as they cannot be prime.* Lets look at number 4. It has been marked as composite because it had 2 as factor. But what about its multiples? We don't have to consider its multiples because they would have been cancelled already as they would have been multiples of factors of 4.* Now we look at 5. Since it has not been cancelled we mark it prime and then mark all its multiples as composites. * We only need to do this process till sqrt(1000). Why

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 Programming Questions!