Ma · Mathematics

How to Check Whether a Number Is Perfect

Published By the 9to5Science editorial team

At a glance

  1. 1. List proper divisors

    Find the positive divisors of n, leaving n itself out.

  2. 2. Add the divisors

    Calculate their sum, using divisor pairs up to the square root to save time.

  3. 3. Compare with n

    The number is perfect exactly when the proper-divisor sum equals n.

  4. 4. Use a factorization

    For a known prime factorization, compute the divisor sum with the sigma formula.

A perfect number is a positive integer equal to the sum of its positive divisors other than itself. You can check a particular number by finding and adding those proper divisors. For larger numbers, pairing divisors or using the prime factorization avoids listing every divisor one by one.

The method works for any positive integer. It also clarifies a useful equivalent test: the sum of all positive divisors must be twice the number.

Definition and equivalent test

Write s(n)s(n) for the sum of the proper positive divisors of nn. Then nn is perfect precisely when

s(n)=n.s(n)=n.

If σ(n)\sigma(n) denotes the sum of all positive divisors, including nn, then σ(n)=s(n)+n\sigma(n)=s(n)+n. Therefore the same test can be written as

σ(n)=2n.\sigma(n)=2n.

For example, the proper divisors of 6 are 1, 2, and 3. Their sum is 6, so 6 is perfect. The number 1 is not perfect: it has no proper positive divisors, so their sum is 0.

Check by pairing divisors

For a number nn, each divisor dd is paired with n/dn/d. One member of the pair is at most n\sqrt n, and the other is at least n\sqrt n. This means you only need to test possible divisors up to the square root.

Use this procedure:

  1. Start the proper-divisor sum at 1 for n>1n>1; 1 is always a proper divisor of such a number.
  2. For each integer dd from 2 through ⌊n⌋\lfloor\sqrt n\rfloor, check whether dd divides nn.
  3. If it does, add both dd and n/dn/d to the sum.
  4. If nn is a square and d=nd=\sqrt n, add that divisor only once.
  5. Compare the result with nn.

For n=28n=28, the divisors found from the test values are 22 and 1414, and 44 and 77. Including 1 gives

1+2+14+4+7=28.1+2+14+4+7=28.

Thus 28 is perfect. The test did not need to check values above 28\sqrt{28}, because any larger proper divisor would have a matching divisor below the square root.

As a square-number example, take n=36n=36. The proper divisors are 1,2,3,4,6,9,12,181,2,3,4,6,9,12,18, whose sum is 55. When testing up to 36=6\sqrt{36}=6, the pair for d=6d=6 is just 66 itself; counting it twice would give the wrong sum. Since 55 is not 36, the number is not perfect.

Use the prime factorization

If you know the prime factorization

n=p1a1p2a2⋯pkak,n=p_1^{a_1}p_2^{a_2}\cdots p_k^{a_k},

you can calculate the sum of all divisors without listing them:

σ(n)=∏i=1k(1+pi+pi2+⋯+piai)=∏i=1kpiai+1−1pi−1.\sigma(n)=\prod_{i=1}^{k}(1+p_i+p_i^2+\cdots+p_i^{a_i}) =\prod_{i=1}^{k}\frac{p_i^{a_i+1}-1}{p_i-1}.

Then check whether σ(n)=2n\sigma(n)=2n. For 28, the factorization is 22⋅72^2\cdot7, so

σ(28)=(1+2+4)(1+7)=7⋅8=56=2⋅28.\sigma(28)=(1+2+4)(1+7)=7\cdot8=56=2\cdot28.

Therefore 28 is perfect. This formula is particularly convenient when a number has few prime factors, though finding the factorization can itself be difficult for very large numbers.

A shortcut for even perfect numbers

There is a special characterization of even perfect numbers: an even integer is perfect exactly when it has the form

2p−1(2p−1),2^{p-1}(2^p-1),

where both pp and the Mersenne number 2p−12^p-1 are prime. For instance, p=3p=3 gives 22(23−1)=4⋅7=282^2(2^3-1)=4\cdot7=28. This shortcut is useful when checking candidates of that form. It does not settle whether any odd perfect numbers exist; that remains an open problem. The divisor-sum test still applies to any specific odd number you want to check.

Common mistakes

  • Including nn among the proper divisors. The proper-divisor sum excludes the number itself. If you use σ(n)\sigma(n) instead, compare it with 2n2n.
  • Counting a square-root divisor twice. When nn is a square, its square root pairs with itself and should be added once.
  • Checking divisors only up to n/2n/2 without a reason. That method can work, but testing up to n\sqrt n and adding divisor pairs is usually faster.
  • Assuming a familiar form proves perfection automatically. For the even-number characterization, verify that both pp and 2p−12^p-1 are prime.

For a single moderate-sized integer, the divisor-pair test is straightforward. For a number already factored into primes, the sigma formula is often shorter.

References

  1. Elementary Number Theory, David M. Burton

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.