Euler/euler21.php

20 lines
425 B
PHP
Raw Normal View History

2015-11-21 14:43:34 +01:00
<?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;