Amicable numbers are pairs of two different numbers, so that the sum of the proper divisors of each is equal to the other number.
What is the sum of amicable numbers under 10000.
First all numbers under 10000
a <- c(1:10000)
Then the sum of the proper divisors of all of them:
library(numbers)
b <- unlist(lapply(a, function(x) sum(divisors(x)[1:(length(divisors(x))-1)])))
These are the numbers that can be amicable with the numbers
in a.
Next the sum of the proper divisors of b:
c <- unlist(lapply(b, function(x) sum(divisors(x)[1:(length(divisors(x))-1)])))
These are the numbers that can be amicable with the numbers
in b.
In total - numbers in a can be amicable with the numbers in
b. And the numbers in c can be amicable with the
numbers in b. Therefore a number in a is amicable with an
number in b, if it is equal to the number in c (with the same index).
Except for the fact that the two amicable numbers in a and be have to be
different:
answer <- sum(a[a==c & a!=b])