欧拉工程-问题21
原题链接 http://projecteuler.net/problem=21
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 !=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.
亲和数
令d(n)为数n的所有真因子(小于n且可以整除n)的和.如果d(a) = b且d(b) = a,并且a != b,那么a和b组成亲和数对,a和b都被称为亲和数。
例如,220的真因子有1,2,4,5,10,11,20,22,44,55和110,则d(220) = 284。284的真因子是1,2,4,71和143,所以d(284) = 220。
找到1000以内所有亲和数的和。
解答:
这题我没想到好的方法,暴力解决,复杂度为 O(n^2),一分钟之内可以得出结果,也就没想再优化了。