If you want a pure iterative solution, you could compute a factor wheel and print everything but the usual trial divisors. The code looks messier, but it requires no mod calculations in the loop, just adds. I computed the wheel using Math::Big::Factors (so for people following the original articles, we have come full circle...).