Question: Math 3 3 4 3 * Homework 4 Consider the pseudocode for computing an array of prime numbers less than or equal to n .
Math Homework
Consider the pseudocode for computing an array of prime numbers less than or equal to
INPUT positive integer
OUTPUT is an array of prime numbers less than or equal to is the number of
prime numbers less than or equal to
for dotsn
for dotsc
if remainder
then is composite, stop loop and go to next value
end if statement
end for loop
If inner loop cycled all the way through
then
then
end if statement
end for loop
The algorithm can be summarized in this way. Consider whether each integer from to is
prime by dividing it by all integers greater than and less than the number being considered.
If one of those lesser numbers divides evenly into our candidate prime, then it's composite.
Otherwise it is prime and we add that candidate number to the list.
This algorithm is implemented in the code primelistslow.m As the code name sug
gests, we can accelerate the speed of the code. That is the subject of this homework.
Theorem If is not divisible by any prime number less than then is a prime number.
Theorem If is not divisible by any integer between two and then is prime.
points Explain how the the two theorems above can be used to accelerate the code
primelistslow.m created in class and available via Blackboard
points Write a pseudocode incorporating these changes with input and output
which is an array of all prime numbers less than or equal to
points Create a Matlab function, titled primelist that implements your pseu
docode above. Your function should have the following input and output:
Input positive integer
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
