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.