26
The sum of all natural numbers (positive integer) of divisors 220 except 220 is equal to:
1 + 2 + 4 + 5 + 10 + 11 + 20 + 22 + 44 + 55 + 110 = 284
And the sum of all natural numbers of divisors 284 except himself is equal to:
1 + 2 + 4 + 71 + 142 = 220
The numbers 220 and 284 are called Friends. Generally, we say that two positive integers are Friends if each of the sum of its divisors (excluding the number itself) is equal to the other number.
Write the program to calculate all numbers Friends from 2 to N.
Example:
If the entrance is N = 1500
the output should be: (284, 220)
, (1210, 1184)
Note: Use the language you prefer.
For those who are negative, please read here: https://pt.meta.stackoverflow.com/questions/1366/desafios-e-code-golf
– user28595
In general, you will need a function that returns a list of the divisors of a given number, another that returns the sum of the values of a list, and for each number from 2 to N, it will take the list of divisors, add to get a "candidate for Friend"then take the candidate’s divisor list and add to compare with the original.
– Haroldo_OK
@Haroldo_ok yes, but do you know what Code Golf is? The challenge is to write a program that manages this result with as few characters as possible.
– Woss