Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

6 : Optimus Prime Consider some p in Z where p > 1 . If the only factors are p , 1 , then p

6: Optimus Prime
Consider some p in Z where p >1. If the only factors are p,1, then p is called a prime number. If
p is not a prime number, then it is called a composite number. Remember, a factor is a number
that integer divides another. Prime numbers are important to cryptography and have fascinated
people for a long time. Lets leverage modulo to find a small list of primes. Using modulo,
implement a Boolean function prime(p) that returns true if p is prime for any positive integer p >1.
Here is code:
1 ps =[]
2 for p in range (2,100):
3 if prime(p):
4 ps.append(p)
5
6 print(ps)
and its behavior:
1[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
Deliverables Programming Problem 6
Complete the prime function.
Given a number p, its prime if no other number p 1, p 2,...,2 is a factor. Do a
little mathematics and reduce the size of the numbers you have to check.
You are only allowed to use modulo and integer division if at all.
- DON'T USE AI AT ALL
########################
# PROBLEM 6
########################
# Input: a number p
# Output: return True if p is prime, False otherwise
def prime(p):
pass

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 2 Lnai 8725

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448505, 978-3662448502

More Books

Students also viewed these Databases questions

Question

b. What groups were most represented? Why do you think this is so?

Answered: 1 week ago

Question

3. Describe phases of minority identity development.

Answered: 1 week ago

Question

5. Identify and describe nine social and cultural identities.

Answered: 1 week ago