Skip to content

Commit 091b592

Browse files
Update sol1.py
1 parent 9dd0d84 commit 091b592

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

project_euler/problem_095/sol1.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
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 -> ...)
10+
Since this chain returns to its starting point, it is called an amicable chain.
11+
Find the smallest member of the longest amicable chain with no element exceeding one million.
12+
613
Solution is doing the following:
714
- Get relevant prime numbers
815
- Iterate over product combination of prime numbers to generate all non-prime
916
numbers up to max number, by keeping track of prime factors
1017
- Calculate the sum of factors for each number
1118
- Iterate over found some factors to find longest chain
12-
13-
>>> solution(200000)
14-
12496
15-
1619
"""
1720

1821
from numpy import sqrt
@@ -113,6 +116,8 @@ def solution(n_max: int = 1000000) -> int:
113116
114117
>>> solution(10)
115118
6
119+
>>> solution(200000)
120+
12496
116121
"""
117122

118123
primes = generate_primes(n_max)

0 commit comments

Comments
 (0)