Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I’m new to using Spacemacs and we are in .org mode. Create a lisp program to gen

ID: 3849609 • Letter: I

Question

I’m new to using Spacemacs and we are in .org mode.

Create a lisp program to generate a prime number that:

1 - Randomly generates an integer.

2 - Then use Fermat's little theorem which states: If "p" is a prime & if "a" is any interger then ap = a (mod p) to determine that there is a high probability that the randomly generated number is prime.

3 - If it can be determined that the number is not prime, then randomly generate another number and try again.

4 - Use your program to generate some data with which to estimate the following probability: Given some randomly generated number p that is NOT prime and some constant a, what is the probability that the congruence in Fermat's little theorem still holds? Specify the range you used to generate random numbers.

5 - Given your estimate of the above probability, what is the probability that your prime number generator fails, meaning that the number it generates is actually not prime? Report your answer and how you calculated it.

Explanation / Answer

(defun primep(n)

(cond

((=1 n) nil)

(true

((loop

:with root =(isqrt n)

:with divisors=(loop : for i:from 3:to root :by 2:collect i)

:for d=(pop divisors)

:if(zerop(mod n d))

:do (return nil)

:else :do(setf divisors(delete-if(lambda(x) (zerop(mod x d))) divisors))

:while divisors

:finally (return true)))))

This lisp program will return true when the no is prime or else it will return nill

So this for this lisp program we cannot use % instead we can use rem function