Staaarter

Generate Almost Perfect Numbers

Generates the first N almost-perfect numbers, every known example is a power of two, by computing 2^k and verifying its proper divisor sum equals 2^k minus 1. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-08-05
By Staaarter Team
number-theorysequences

Overview

Introduction

Almost-perfect numbers, sometimes called least deficient numbers, are a special case one step away from perfect numbers on the divisor-sum spectrum.

This generator lists the sequence's known terms, all of which are powers of two, and verifies each one's divisor sum matches the defining property before including it.

What Is Generate Almost Perfect Numbers?

An almost-perfect number is a positive integer whose proper divisors sum to exactly one less than the number itself, giving it a deficiency of 1.

Every power of two fits this definition: for 2^k, the proper divisors 1, 2, 4, ..., 2^(k-1) form a geometric series that sums to 2^k - 1, exactly one short of 2^k.

How Generate Almost Perfect Numbers Works

The tool computes successive powers of two, 2^0, 2^1, 2^2, and so on, using BigInt arithmetic so terms stay exact no matter how large they get.

For each power, it tracks the running sum of all smaller powers of two already generated, which equals that term's proper divisor sum, and confirms it's exactly one less than the term before adding it to the output.

When To Use Generate Almost Perfect Numbers

Use it when studying the deficiency function in number theory, or when you need a quick reference list of powers of two framed through their divisor-sum property.

It's also a useful teaching example for showing how a geometric series identity (the sum of powers of two) connects directly to a classical number-theory classification.

Features

Advantages

  • Uses exact BigInt arithmetic, so terms remain precise even as powers of two grow into very large numbers.
  • Every output term is internally verified against the deficiency-of-1 definition before being included, not just assumed from the power-of-two pattern.
  • Runs instantly since powers of two are computed directly rather than searched for by brute force.

Limitations

  • Capped at 1000 terms, since powers of two beyond that grow far too large to be a practically useful display, even though the underlying computation would still be exact.
  • Only outputs the proven sequence of powers of two; it cannot search for hypothetical non-power-of-two almost-perfect numbers, since none are known to exist.

Examples

First 6 almost-perfect numbers

Input

6

Output

1, 2, 4, 8, 16, 32

Each term is a power of two; for example 16's proper divisors 1, 2, 4, 8 sum to 15, exactly one less than 16.

Best Practices & Notes

Best Practices

  • Request a modest term count, the values double each time, so even 20 terms already reach into the millions.
  • Pair this with Perfect Number Generator to contrast a deficiency-of-1 sequence against the deficiency-of-0 case.

Developer Notes

Each term is produced with `1n << BigInt(exponent)` and validated against a running BigInt accumulator of prior terms, an internal-consistency check that doubles as a safeguard against a future implementation error silently breaking the deficiency-of-1 guarantee.

Generate Almost Perfect Numbers Use Cases

  • Studying the deficiency function and its relationship to divisor sums in number theory
  • Classroom demonstrations connecting the geometric series formula to a divisor-sum classification
  • Quick reference list of powers of two framed by their proper-divisor-sum property

Common Mistakes

  • Assuming almost-perfect numbers exist beyond powers of two, no others have ever been found or proven, so treat the sequence as this specific, proven set.
  • Confusing deficiency-of-1 (almost-perfect) with the broader deficient-number category, which just means the divisor sum is less than the number by any amount.

Tips

  • The term count doubles at every step, so if you need a specific magnitude, work backward from log2 of your target value to pick the right term count.
  • Use Deficient Number Sequence Generator if you want the full, broader set of numbers with any degree of deficiency, not just deficiency of 1.

References

Frequently Asked Questions