function p = prim(n)
% function p = prim(n)
if n<2
  p = zeros(0,1);
elseif n<3
  p = 2;
else
  p = [2
       3];
  i = 2;
end
for m=5:2:n
  k = ceil(sqrt(m));
  for j=3:2:k
    div = rem(m,j)==0;
    if div, break, end
  end
  if ~div
    i = i+1;
    p(i) = m;
  end
end
