#!/usr/bin/perl -w use strict; $| = 1; chomp(my $max = ); print "\n2 "; N: for (my $i = 3; $i < $max; $i += 2) { next unless $i % 6 == 5 or $i % 6 == 1; for (my $k = 3; $k < sqrt $i; $k += 2) { next N if $i % $k == 0; } print $i, " "; } print "\n";