**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
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
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.