23.jl 747 B

123456789101112131415161718192021222324252627282930313233343536
  1. # Upper bound for sums
  2. limit = 28123
  3. function isabundant(n)
  4. factor_sum = 0
  5. for i = 1:(n - 1)
  6. if n % i == 0
  7. factor_sum += i
  8. end
  9. end
  10. return factor_sum > n
  11. end
  12. # Array of all possible abundant numbers
  13. all_abundants = filter(isabundant, [1:limit])
  14. # Create array of whether an integer can be expressed as a sum of 2 abundants
  15. sumOfAbundant = falses(limit)
  16. for i = all_abundants
  17. for j = all_abundants
  18. if i + j <= limit
  19. sumOfAbundant[i + j] = true
  20. else
  21. break
  22. end
  23. end
  24. end
  25. # Sum up integers that cannot be expressed as sum of abundants
  26. sum = 0
  27. for (index, value) in enumerate(sumOfAbundant)
  28. if !value
  29. sum += index
  30. end
  31. end
  32. println(sum)