|
3 | 3 |
|
4 | 4 | Amicable Chains |
5 | 5 |
|
6 | | -The proper divisors of a number are all the divisors excluding the number itself. For example, the proper divisors of 28 are 1, 2, 4, 7, and 14. As the sum of these divisors is equal to 28, we call it a perfect number. |
7 | | -Interestingly the sum of the proper divisors of 220 is 284 and the sum of the proper divisors of 284 is 220, forming a chain of two numbers. For this reason, 220 and 284 are called an amicable pair. |
8 | | -Perhaps less well known are longer chains. For example, starting with $12496$, we form a chain of five numbers: |
9 | | -12496 -> 14288 -> 15472 -> 14536 -> 14264 (-> 12496 -> ...) |
| 6 | +The proper divisors of a number are all the divisors excluding the number itself. |
| 7 | +For example, the proper divisors of 28 are 1, 2, 4, 7, and 14. |
| 8 | +As the sum of these divisors is equal to 28, we call it a perfect number. |
| 9 | +
|
| 10 | +Interestingly the sum of the proper divisors of 220 is 284 and the sum of the proper divisors of 284 is 220, |
| 11 | +forming a chain of two numbers. For this reason, 220 and 284 are called an amicable pair. |
| 12 | +
|
| 13 | +Perhaps less well known are longer chains. |
| 14 | +For example, starting with 12496, we form a chain of five numbers: |
| 15 | + 12496 -> 14288 -> 15472 -> 14536 -> 14264 (-> 12496 -> ...) |
| 16 | +
|
10 | 17 | Since this chain returns to its starting point, it is called an amicable chain. |
| 18 | +
|
11 | 19 | Find the smallest member of the longest amicable chain with no element exceeding one million. |
12 | 20 |
|
13 | 21 | Solution is doing the following: |
14 | 22 | - Get relevant prime numbers |
15 | 23 | - Iterate over product combination of prime numbers to generate all non-prime |
16 | | -numbers up to max number, by keeping track of prime factors |
| 24 | + numbers up to max number, by keeping track of prime factors |
17 | 25 | - Calculate the sum of factors for each number |
18 | 26 | - Iterate over found some factors to find longest chain |
19 | 27 | """ |
|
0 commit comments