% smallestfactor(n) - smallest integer factor
function res = smallestfactor(n)
res = n; %! Assume $n$ is prime until we find a factor $\leq \sqrt{n}$
for k=2:sqrt(abs(n))
   if rem(n,k) == 0 %! Is \code{k} a factor?
      res = k; %! Yes, so record it and
      break; %! don't look any further.
   end
end
