Check prime number or not in constant time(without using any loop) | MATLAB


Code:

clc
clear all
close all
x=input('Enter the number:');
if(x==2 || x==3)
    disp('Prime number');
elseif(rem((x-1),6)==0 || rem((x+1),6)==0)
    disp('Prime number');
else
    disp('Not a prime number');
end


No comments