Project Euler – Problem 23 (Python Solution)

Non-abundantsums.jpeg

This a complex, multi-step problem. First I had to write an algorithm to find the sum of all proper divisors of a number ‘n’:

sum_divisors.jpeg

This was simple enough, and using this sub-routine, I could produce a list of all abundant numbers underneath my limit of 28123:

abundantlist

I then had to find a way to check if a number could be made from 2 abundant numbers. I did this by starting with the first number and binary searching for its complement (n-a = c) and made my way through the list.

If a pair was never found, the number was added onto a running total of number that were not produceable from abundant numbers

make a number

The search algorithm was just a classic binary search:

binsearch.jpeg

When the upper limit was reached, the total can be outputted.

sumofnotpossible

This produced the answer:

4179871

In 83.2934291363 seconds

Thanks for reading!

 

Leave a comment