All pastes #904357 Raw Edit

Primes via trial division by you

public text v1 · immutable
·published 2008-02-14 21:55 UTC
rendered paste body
#prime numbers

my $start = (times)[0];

print "1\n2\n";

$bound = 9998;
$curr = 3;
$cnt = 1;

while ($cnt <= $bound)
{
	$err = 0;
	$i = 3;
	while ($i <= sqrt($curr))
	{
		if ($curr % $i == 0)
		{
			break;
			$err = 1;
		}
	#increment $i to skip even numbers
	$i+=2;
	}
	if ($err == 0)
	{
	#Number is prime
		print $curr ."\n";
		$cnt++;
	}
	$curr+=2;
}

my $end = (times)[0];
printf("RUNTIME: %.2f CPU seconds.", $end - $start);