Skip to content

Commit 2d04e70

Browse files
Update sol1.py
1 parent 091b592 commit 2d04e70

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

project_euler/problem_095/sol1.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,25 @@
33
44
Amicable Chains
55
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+
1017
Since this chain returns to its starting point, it is called an amicable chain.
18+
1119
Find the smallest member of the longest amicable chain with no element exceeding one million.
1220
1321
Solution is doing the following:
1422
- Get relevant prime numbers
1523
- 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
1725
- Calculate the sum of factors for each number
1826
- Iterate over found some factors to find longest chain
1927
"""

0 commit comments

Comments
 (0)