sum(s for s in range(1,(n//2)) if
((n/s)%1)==0)
1からある数n//2(nの半分)までの数
(完全数はn⾃⾝は含まない)
sは1からn//2までの整数
n/sが1で割り切れる(余りなしなので約数)
sum()内はリスト内包表記のジェネレータとなる
sum()で合計
next(n for n in count(1,2) if (約数の合
計)==n)"
count() (itertools.count())で奇数を取得
約数の合計がある数nになるものを探す
next()内はジェネレータとなる
next()でジェネレータを⼀つ進める
itertools.count()は標準モジュールなのでセーフ
(ということにしている)
125⽂字
In [2]: len('''python -c "from itertools import *; print
(next(n for n in count(1,2) if sum(s for s in range(1,(n//2)) if ((n
/s)%1)==0)==n))"''')
Out[2]: 125")