| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

021

Page history last edited by Kenneth Finnegan 15 years, 4 months ago

Project Euler Problem #21

This solution wasn't very elegant.  I first brute force factored each number in 2-10,000.  This was done by looping from 2 to number/2 (since in 2*x, x is the largest possible factor).   This is where the largest imprevement could be done as far as speed improvements.  I then iterated through the list, avoiding numbers that where above 10,000 (segmentation fault, out of array bound), and avoiding numbers that were amicable with themselves, to find all the amicable pairs, which followed the condition number == array[array[number]].  This is because the sum of the factors should equal another number, who's summed factors should equal the first.

 

Runtime: 2.325s

PE021_c

 


Return to list of solutions

Comments (0)

You don't have permission to comment on this page.