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

**This question is a all in one question. Number 3 requires questions 1 and 2. I

ID: 3815700 • Letter: #

Question

**This question is a all in one question. Number 3 requires questions 1 and 2. I know there is somewhat a limit but this is 1 Lab which is an all in one question. Please answer them all i'd greatly appreciate it. I have question 1 done but need help with the rest of them.**

Answer for the first question:

prompt = 'Enter the value of P';
p = input(prompt); %taking the input
p = uint64(p); %convert p to double to unsigned integer
if(mod((factorial(p-1)+1),p)==0) %checking the condition for p whether it is prime or not
disp('p is prime')
else
disp('p is not a prime')
end

In this lab, we will use MATLAB to implement primality tests, namely Fermat's little theorem and Wilson's Theorem. We will also implement Fermat's Last Theorem 1. Wilson's Theorem (25 points) (p 1)! 1 Wilson's theorem states that a number p is prime if and only if the remainder of is 0 Implement Wilson's Theorem to determine whether a number is prime or not. Hint: In MATLAB when you receive your input variable, p, use the following statement p uint64 (p to convert p from a double to an unsigned integer that ranges from 0 to 18,446,744,073,709, 551,61 2. Fermat's Little Theorem (25 points) Fermat's little theorem states that a number p is prime if for all numbers a such that 1 S a p ap-1 is 0. Implement Fermat's Little Theorem. Hint: As done in Problem 1 the remainder of 3. Speed Test (25 points) Use MATLAB's tic and toc function to determine the speed of determining whether a number p is prime or not using MATLAB's built-in isprime, MATLAB's built-in factor function, Wilson's Theorem, and Fermat's Little Theorem. Display the times of each function 4. Fermat's Last Theorem (25 points) Fermat's Last Theorem states that no three positive integers a,b, and c can satisfy the equation a" b" E c for any integer value of n greater than two (From Wikipedia)." For n 2, we have the Pythagorean triples such as 13, 4, 5 where 32 42 52. In MATLAB, empirically verify Fermat's Last Theorem for bounded values of a. b. and c as seen below: 1 5 2 6 3 5 where a is the set of integers from 1 to 5, b is the set of integers from 2 to 6, and c is the set of integers from 3 to 5. To receive input from the user as a matrix, use the code below data str2num (input ('Enter the bounds for a, b, and c 's')); Enter the bounds for a, b, and c 1 5; 2 6; 3 5 will save the matrix seen above in data. Also, take as input from the user the value of n. If the user inputs 2 for n, a sample output is given below a a b b2 a b c c Equal? 3 9 False 1 4 3 9 4 16 25 5 25 True 5 25 6 36 61 5 25 False

Explanation / Answer

[1]

function [] = Wilson_Theorm(p)

p = uint64(p);

% define local variable

sum = 1;

% Define the range of a

for i = 1 : p-1

sum = sum * i ;

% end of for loop

end

sum = sum + 1 ;

% Logic to display the Result

if (rem(sum,p) ~= 0)

disp('Not an Prime Number');

else

disp('An Prime Number');

end

%end of function

end


[2]

function [] = Fermat_Little(p)

% define local variable
count = 0;
% Define the range of a
for i = 1 : p-1
   a = i ;
   upper = a.^(p-1) - 1;
   lower = p;
   count = count + 1;
    
     % To check the reminder is equal to 0 or not
     if( rem(upper,lower) ~= 0)
      % if condition satisfied then teminate the loop
   break
     %end of if loop
     end
    
% end of for loop
end


% Logic to display the Result
if (count ~= p-1)
     disp('Not an Prime Number');
else
    disp('An Prime Number');
end   


%end of function

end