Amicable Numbers

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 \ne 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$.

The approach used to solve this question involves calculating the sum of all divisors of each number under 10,000 and then checking if it forms an amicable pair with another number.

Let’s write this out in the form of code using Python:

“`python
import math

def divisors(n):
result = [1]
for i in range(2, math.isqrt(n) + 1):
if n % i == 0:
if n // i == i:
result.append(i)
else:
result.extend([i, n // i])
return result

def amicable_numbers(limit):
d = [sum(divisors(n)) for n in range(limit)]
result = [i for i in range(limit) if d[i] < limit and i == d[d[i]] and i != d[i]] return result print(sum(amicable_numbers(10000))) ``` In this code, the function `divisors` calculates all the divisors of a number `n`. The function `amicable_numbers` determines the sum of all proper divisors (`d(n)`) for all numbers up to the `limit` (excluding the `limit`). It then checks if for these numbers, `d(d(n)) = n` and `n != d(n)` to determine if they form an amicable pair and adds them to `result` list. Finally, the print statement calls `amicable_numbers` function with `limit` equal to 10,000 and prints the result. This code prints the result as 31,626, which is the sum of all the amicable numbers under 10,000.

More Answers:
Maximum Path Sum I
Counting Sundays
Factorial Digit Sum

Error 403 The request cannot be completed because you have exceeded your quota. : quotaExceeded

Share:

Recent Posts