21
This commit is contained in:
parent
05f6ddc897
commit
5177729721
21
euler21.php
Normal file
21
euler21.php
Normal 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;
|
Loading…
Reference in New Issue
Block a user