Simplify `perfect_number` function.