Posts tonen met het label amicable. Alle posts tonen
Posts tonen met het label amicable. Alle posts tonen

zondag 20 februari 2011

Euler problem 21

Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n).
If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and b are called amicable numbers.
For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220.
Evaluate the sum of all the amicable numbers under 10000.




Performance improvements:

1) Eliminate doubleness by limit the search to a > b.
2) Search dividers until sqrt(n). Boost 489 ms -> 3,6 ms.



Problem21 =       31626 elapsed time:    3 ms. Test Passed.