Return to Snippet

Revision: 13659
at April 30, 2009 18:30 by cobra90nj


Updated Code
<?php

/**
cobra90nj@cobra90nj:~/Scrivania$ time php ll.php
104760
real	0m46.014s
user	0m42.267s
sys	0m0.056s
*/

function isPrime($num) 
{
	if ($num == 2 || $num == 3) { return 1; }
	if (!($num%2) || $num<1)    { return 0; }
	
	for ($n = 3; $n <= $num/2; $n += 2) {
		if (!($num%$n)) {
			return 0;
		}
	}
	
	return 1;
}

$obb  = 1; 
$ispr = 4;

while ($obb < 10001) {
	
	if (isPrime($ispr)) {
		 $obb++;
		 $ispr++;
 	}
 	else {
 		$ispr++;
	}
}

echo $ispr;

Revision: 13658
at April 30, 2009 18:30 by cobra90nj


Initial Code
<?php

function isPrime($num) 
{
	if ($num == 2 || $num == 3) { return 1; }
	if (!($num%2) || $num<1)    { return 0; }
	
	for ($n = 3; $n <= $num/2; $n += 2) {
		if (!($num%$n)) {
			return 0;
		}
	}
	
	return 1;
}

$obb  = 1; 
$ispr = 4;

while ($obb < 10001) {
	
	if (isPrime($ispr)) {
		 $obb++;
		 $ispr++;
 	}
 	else {
 		$ispr++;
	}
}

echo $ispr;

Initial URL

                                

Initial Description

                                

Initial Title
Project euler 7

Initial Tags

                                

Initial Language
PHP