Project Euler Problem 12

What is the value of the first triangle number to have over five hundred divisors?

<?php
function factorcount($num) {
	$i = 1;
	$sqrt = sqrt($num);
	while($i <= $sqrt) {
		if($num % $i == 0) {
			$arr[] = $i;
		}
		$i++;
	}
	$count = count($arr) * 2;
	if (preg_match('/^[0-9]+$/', sqrt($num))) {
		$count--;
	}
	return $count;
}
$run = true;
$i = 1;
$sum = 0;
while($run) {
	$sum += $i;
	if(factorcount($sum) > 500) {
		echo $sum
		$run = false;
	}
	$i++;
}
?>

Leave a Reply

Your email address will not be published.