ONLY DO WHAT ONLY YOU CAN DO

こけたら立ちなはれ 立ったら歩きなはれ

Project Euler Problem 21

10000未満の友愛数の和を求めよ

を n の真の約数の和と定義する. (真の約数とは n 以外の約数のことである. )
もし, かつ (a ≠ b のとき) を満たすとき, a と b は友愛数(親和数)であるという.

例えば, 220 の約数は 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110 なので である.
また, 284 の約数は 1, 2, 4, 71, 142 なので である.

それでは10000未満の友愛数の和を求めよ.

Amicable numbers

Let be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n).
If and , 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 . The proper divisors of 284 are 1, 2, 4, 71 and 142; so .

Evaluate the sum of all the amicable numbers under 10000.

考え方

自然数 n が、

(素数 は 0 以上の整数)
素因数分解されるとき、n の約数の個数と 約数の総和は、次の公式で与えられる。
約数の個数:
約数の総和:

たとえば、 は、素因数分解され、約数は、






で、約数の個数 は、 個、
約数の総和は


である。