Project Euler with Ruby on WSL [Problem 23]

書くことがない?

特にないな

問題

Non-abundant sums

A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.

A number n is called deficient if the sum of its proper divisors is less than n and it is called abundant if this sum exceeds n.

As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematical analysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit.

Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.

私訳

過剰数

過剰数 n とは、n の真の約数*1の和が n を超えるものである

最小の過剰数は 12 で、1+2+3+4+6=16 である。よって、2つの過剰数の和で書ける最小の数は 24 である。 解析的に 28123 を超えるすべての数は過剰数の和で書けることが知られている。 しかし、過剰数の和で書けない数はこれより小さいこと知られている。

正整数のうち、2 つの過剰数の和で書けないものの和を求めよ

解答方針

うーん。ぱっとはわからないのでとりあえず過剰数を適当にリストアップしてみましょう。 => [12, 18, 20, 24, 30, 36, 40, 42, 48, 54, 56, 60, 66, 70, 72, 78, 80, 84, 88, 90, 96] 奇数がないですね。奇数がないと和から奇数が作れない。

…。だめだ。愚直にやろう。 28123 未満の過剰数を列挙し、これらの和をすべてカウントして、 集合を反転しましょう…。

*1:つまり n を除く