Skip to main content
LeetCode 507, Easy. Topics: Math. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 23 parametrized pytest cases, and a playground notebook:

Problem

A <a href=“https://en.wikipedia.org/wiki/Perfect_number” target=“_blank”><strong>perfect number</strong></a> is a <strong>positive integer</strong> that is equal to the sum of its <strong>positive divisors</strong>, excluding the number itself. A <strong>divisor</strong> of an integer <code>x</code> is an integer that can divide <code>x</code> evenly. Given an integer <code>n</code>, return <code>true</code><em> if </em><code>n</code><em> is a perfect number, otherwise return </em><code>false</code>.

Examples

Constraints

  • 1 <= num <= 10^8

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026