(Prime Testing) A positive integer n is prime if it is greater than or equal to two and it is evenly divisible by only 1 and itself (n). Therefore, we can test this divisibility against all numbers between 2 and n – 1 to determine if a given number is prime. (In fact, this can be sped up by stopping at vn instead of n - 1.) For this problem do not use the built in isprime function (or any other function which trivializes the problem). Also, do not use the break command since it is a bad programming practice and I would like to discourage its use. is_prime Function: Input variables: • a single number representing n; if n is a positive integer, we wish to determine if it is prime, and otherwise will simply return 0 (false). Output variables: • a boolean representing whether or not the given n was prime. A possible sample case is: » is_p = is_prime(7) is p = 1 » is_p = is_prime(16) is_p = 0 » is_p = is_prime(-1) is p = 0 » is_p = is_prime(pi) is p = 0
(Prime Testing) A positive integer n is prime if it is greater than or equal to two and it is evenly divisible by only 1 and itself (n). Therefore, we can test this divisibility against all numbers between 2 and n – 1 to determine if a given number is prime. (In fact, this can be sped up by stopping at vn instead of n - 1.) For this problem do not use the built in isprime function (or any other function which trivializes the problem). Also, do not use the break command since it is a bad programming practice and I would like to discourage its use. is_prime Function: Input variables: • a single number representing n; if n is a positive integer, we wish to determine if it is prime, and otherwise will simply return 0 (false). Output variables: • a boolean representing whether or not the given n was prime. A possible sample case is: » is_p = is_prime(7) is p = 1 » is_p = is_prime(16) is_p = 0 » is_p = is_prime(-1) is p = 0 » is_p = is_prime(pi) is p = 0
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
make mathlab code
![**Prime Testing**
A positive integer \( n \) is prime if it is greater than or equal to two and it is evenly divisible by only 1 and itself (\( n \)). Therefore, we can test this divisibility against all numbers between 2 and \( n - 1 \) to determine if a given number is prime. (In fact, this can be sped up by stopping at \(\sqrt{n}\) instead of \( n - 1 \).)
For this problem *do not* use the built-in `isprime` function (or any other function which trivializes the problem). Also, do not use the `break` command since it is a bad programming practice and I would like to discourage its use.
**is_prime Function:**
- **Input variables:**
- a single number representing \( n \); if \( n \) is a positive integer, we wish to determine if it is prime, and otherwise will simply return 0 (false).
- **Output variables:**
- a boolean representing whether or not the given \( n \) was prime.
A possible sample case is:
```
>> is_p = is_prime(7)
is_p = 1
>> is_p = is_prime(16)
is_p = 0
>> is_p = is_prime(-1)
is_p = 0
>> is_p = is_prime(pi)
is_p = 0
```](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F93507587-8486-4bd1-9be9-7c1c5dc70b2a%2Fcc4d11d1-a421-4c53-9bff-27a098d0d898%2Fk9vubjn_processed.png&w=3840&q=75)
Transcribed Image Text:**Prime Testing**
A positive integer \( n \) is prime if it is greater than or equal to two and it is evenly divisible by only 1 and itself (\( n \)). Therefore, we can test this divisibility against all numbers between 2 and \( n - 1 \) to determine if a given number is prime. (In fact, this can be sped up by stopping at \(\sqrt{n}\) instead of \( n - 1 \).)
For this problem *do not* use the built-in `isprime` function (or any other function which trivializes the problem). Also, do not use the `break` command since it is a bad programming practice and I would like to discourage its use.
**is_prime Function:**
- **Input variables:**
- a single number representing \( n \); if \( n \) is a positive integer, we wish to determine if it is prime, and otherwise will simply return 0 (false).
- **Output variables:**
- a boolean representing whether or not the given \( n \) was prime.
A possible sample case is:
```
>> is_p = is_prime(7)
is_p = 1
>> is_p = is_prime(16)
is_p = 0
>> is_p = is_prime(-1)
is_p = 0
>> is_p = is_prime(pi)
is_p = 0
```
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
Introduction
Prime number: A number is said to be prime if the number has two factors, called one and itself. Then the number is called a prime number. There will be no other factors except 1 and itself.
For example, consider 6 . The factors of the 6 are 1,2,3 and 6. It has more than two factors 1 and itself. So, 6 is not a prime number.
Consider 5, the factors of the 5 are 1 and 5. Therefore, 5 is a prime number.
Step by step
Solved in 3 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education