From 823b0a332add3d0a9ff3a0240465cf2c5e04b432 Mon Sep 17 00:00:00 2001 From: FuryFire Date: Wed, 14 Mar 2012 13:54:21 +0100 Subject: [PATCH] Solved ProjectEuler/023: php --- ProjectEuler/023/desc.yml | 17 +++++++++++++++++ ProjectEuler/023/solve.php | 27 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 ProjectEuler/023/desc.yml create mode 100644 ProjectEuler/023/solve.php diff --git a/ProjectEuler/023/desc.yml b/ProjectEuler/023/desc.yml new file mode 100644 index 0000000..4dfc911 --- /dev/null +++ b/ProjectEuler/023/desc.yml @@ -0,0 +1,17 @@ +title: Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers. +url: http://projecteuler.net/problem=23 + +desc: | + A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number. + A number n is called deficient if the sum of its proper divisors is less than n and it is called abundant if this sum exceeds n. + As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematical analysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit. + Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers. +| + +todo: Improve algorithm +solution: From we http://mathworld.wolfram.com/AbundantNumber.html we cheat and limit our search to 20161 + +solutions: + solve.php: + desc: Very slow - takes around 1 minut on my Core 2 Duo + language: php \ No newline at end of file diff --git a/ProjectEuler/023/solve.php b/ProjectEuler/023/solve.php new file mode 100644 index 0000000..0e4979a --- /dev/null +++ b/ProjectEuler/023/solve.php @@ -0,0 +1,27 @@ + $input) + return true; + } + } + return false; +} +//Find all abundant numbers +for($number = 12; $number <= 28123 ; $number++) { + if(abundant($number)) { $adjnum[] = $number; } +} + +$sum = array_sum(range(1,23)); +for($test = 24; $test <= 20162; $test++) { + $nadundant = true; + for($index = 0; $adjnum[$index] < $test; $index++) { + if(abundant($test - $adjnum[$index])) {$nadundant = false; break; } + } + if($nadundant) {$sum += $test; } +} +echo $sum; \ No newline at end of file