codingtests/solutions/ProjectEuler/020/solve.php

15 lines
266 B
PHP
Raw Normal View History

2012-03-09 12:56:02 +00:00
<?php
define('FACTORIAL',100);
function factorial($num) {
if($num == 0)
return 1;
else
return bcmul($num,factorial(bcsub($num,1)));
}
$sum = 0;
$fac = factorial(FACTORIAL);
for($c = 0; $c < strlen($fac); $c++) {
$sum += $fac[$c];
}
echo $sum;