This commit is contained in:
Gnieark 2015-11-21 14:43:34 +01:00
parent 05f6ddc897
commit 5177729721

21
euler21.php Normal file
View File

@ -0,0 +1,21 @@
<?php
/*
* Gnieark's anwser to euler problem 21
* https://projecteuler.net/problem=21
*/
include("_functions.php");
$sumOfDivisors=array();
for($i=1;$i<10000;$i++){
$sumOfDivisors[$i]=array_sum(getAllDivisors($i,true,false));
}
$sum=0;
//If d(a) = b and d(b) = a, where a ≠ b,
foreach($sumOfDivisors as $a => $d){
if((isset($sumOfDivisors[$d])) && ($sumOfDivisors[$d]==$a) && ($a<>$d)){
$sum+=$a;
}
}
echo $sum;