Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9007339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:39:46+00:00 2026-06-16T01:39:46+00:00

I am solving Problem 23 of Project Euler using Mathematica: Find the sum of

  • 0

I am solving Problem 23 of Project Euler using Mathematica:

Find the sum of all positive integers that cannot be written as the sum of two abundant numbers.

Recall that an abundant number # is one such that Total[Divisors[#]] - # > #. Here is my code:

list1 = Table[i, {i, 1, 28123}];
list2 = Select[list1, Total[Divisors[#]] - # > # && 2 * # < 28123 &];
list3 = {};
l = Length[list2];
For[i = 1, i <= l, i++, 
 For[j = i, j <= l, j++, 
  list3 = Append[list3, list2[[i]] + list2[[j]]]]];
Total[Complement[list1, list3]]

It is extremely slow; the nested For loops take an insane amount of time to evaluate.

Am I approaching this problem correctly? Is there a way to make it faster?

Edit: the reason behind the 28123 is that any number greater than it can be written as the sum of two abundant numbers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:39:48+00:00Added an answer on June 16, 2026 at 1:39 am

    Replace your loops that make list3 by this.

    list3 = (list2[[#]] + list2[[# ;; -1]]) & /@ Range[Length[list2]] // Flatten;
    

    Timing gives 0.49 seconds on my old PC

    update

    To answer a complain that list3 as constructed in my answer gives wrong solution.

    Well. It gives the same content as list3 build using the original code. This method is just faster. If the construction in the original method is wrong, then nothing I can do about that really, since the question was about how to make it faster, not correct any errors in the algorithm itself, which I am not familiar with. The assumption was the algorithm posted was correct but slow.

    (*28123  replaced with smaller value to check, else will take forevever*)
    (*for original algorithm to finish *)
    
    n = 200;
    list1 = Table[i, {i, 1, n}];
    list2 = Select[list1, Total[Divisors[#]] - # > # && 2*# < n &];
    list3 = {};
    l = Length[list2];
    For[i = 1, i <= l, i++, 
      For[j = i, j <= l, j++, 
       list3 = Append[list3, list2[[i]] + list2[[j]]]]];
    
    
    mylist3 = (list2[[#]] + list2[[# ;; -1]]) & /@ Range[Length[list2]] //Flatten;
    

    compare

    list3 - mylist3
    

    Mathematica graphics

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For solving project euler problem 20 to find the sum of digits in 100!
I'm trying to solving Project Euler Problem 14 . It asks to find the
I was solving a Project Euler problem that goes as follows: By considering the
I am solving problem 9 on the Project Euler . In my solution I
Problem 17 on project euler states: If the numbers 1 to 5 are written
I'm playing with Haskell and Project Euler's 23rd problem. After solving it with lists
Possible Duplicate: Need help solving Project Euler problem 200 Similar to this question Project
I am solving Project Euler Problem 11 . I have copy-pasted the table in
I'm working on solving the Project Euler problem 25: What is the first term
I take no credit for this challenge at all. It's Project Euler problem 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.