All Euler problems
Project Euler

Non-Abundant Sums

A positive integer n is perfect if s(n) = n, deficient if s(n) < n, and abundant if s(n) > n, where s(n) = sigma_1(n) - n is the sum of proper divisors. It is known that every integer greater than...

Source sync Apr 19, 2026
Problem #0023
Level Level 01
Solved By 115,113
Languages C++, Python
Answer 4179871
Length 474 words
linear_algebranumber_theoryanalytic_math

Problem Statement

This archive keeps the full statement, math, and original media on the page.

A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of \(28\) would be \(1 + 2 + 4 + 7 + 14 = 28\), which means that \(28\) is a perfect number.

A number \(n\) is called deficient if the sum of its proper divisors is less than \(n\) and it is called abundant if this sum exceeds \(n\).

As \(12\) is the smallest abundant number, \(1 + 2 + 3 + 4 + 6 = 16\), the smallest number that can be written as the sum of two abundant numbers is \(24\). By mathematical analysis, it can be shown that all integers greater than \(28123\) can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit.

Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.

Problem 23: Non-Abundant Sums

Mathematical Development

Definitions

Definition 1 (Abundant Number). A positive integer nn is abundant if s(n)>ns(n) > n, equivalently σ1(n)>2n\sigma_1(n) > 2n.

Definition 2 (Abundant-Sum Representability). A positive integer mm is abundant-sum representable if there exist abundant numbers a,ba, b (not necessarily distinct) such that m=a+bm = a + b. Denote the set of such integers by A2\mathcal{A}_2.

Theorems and Proofs

Theorem 1 (Smallest Abundant Number). The smallest abundant number is 1212.

Proof. We verify exhaustively that s(n)ns(n) \leq n for all 1n111 \leq n \leq 11:

nn1234567891011
s(n)s(n)01131617481

In particular, s(6)=6s(6) = 6 (perfect) and s(n)<ns(n) < n for all other n11n \leq 11. For n=12n = 12: s(12)=1+2+3+4+6=16>12s(12) = 1 + 2 + 3 + 4 + 6 = 16 > 12. \square

Theorem 2 (Closure Under Scaling). If nn is abundant and k2k \geq 2 is a positive integer, then knkn is abundant.

Proof. For each divisor dd of nn, the integer kdkd divides knkn. Hence {kd:dn}{d:dkn}\{kd : d \mid n\} \subseteq \{d : d \mid kn\}, which gives

σ1(kn)dnkd=kσ1(n).\sigma_1(kn) \geq \sum_{d \mid n} kd = k\,\sigma_1(n).

Since nn is abundant, σ1(n)>2n\sigma_1(n) > 2n, so σ1(kn)kσ1(n)>2kn\sigma_1(kn) \geq k\,\sigma_1(n) > 2kn, and therefore s(kn)=σ1(kn)kn>kns(kn) = \sigma_1(kn) - kn > kn, establishing that knkn is abundant. \square

Corollary 1. Every positive multiple of 12 that is at least 24 is abundant. More generally, every positive multiple of any abundant number (with multiplier 2\geq 2) is abundant.

Theorem 3 (Finite Complement of A2\mathcal{A}_2). Every integer greater than 2812328123 belongs to A2\mathcal{A}_2.

Proof. This is a classical result. By Corollary 1, all multiples of 12 from 24 onward are abundant. Since abundant numbers have positive asymptotic density (Schur, 1931; Davenport, 1933 showed the density is approximately 0.2477), the sumset A2\mathcal{A}_2 contains all sufficiently large integers. The bound 28123 has been verified computationally as sufficient. \square

Remark. The largest integer not in A2\mathcal{A}_2 is known to be 20161, so 28123 is a conservative but correct upper bound.

Editorial

We first precompute s(n)s(n), the sum of proper divisors, for every nNn \le N with a sieve-like pass over multiples. From that table we collect the abundant numbers, enumerate all sums of two abundant numbers that stay within the limit, mark those sums as representable, and finally add every unmarked integer. This is sufficient because any number that can be written as a sum of two abundant numbers will be marked during the nested scan.

Pseudocode

Algorithm: Sum of Integers Not Expressible as Two Abundant Numbers
Require: An upper bound N.
Ensure: The sum of all positive integers up to N that are not representable as a sum of two abundant numbers.
1: Compute s(n) for every 1 ≤ n ≤ N by distributing each divisor d to the proper multiples of d.
2: Collect all abundant numbers into a list A ← {n : s(n) > n}.
3: Initialize a Boolean table mark on {0, 1, ..., N}; for each pair a, b in A with a + b ≤ N, set mark[a + b] ← true.
4: Compute S ← sum of all n with 1 ≤ n ≤ N and mark[n] = false.
5: Return S.

Complexity Analysis

Proposition. The algorithm runs in O(NlogN+A2)O(N \log N + A^2) time and O(N)O(N) space, where A={nN:n is abundant}A = |\{n \leq N : n \text{ is abundant}\}|.

Proof.

  • Step 1 (Sieve): The inner loop for each ii iterates N/i1\lfloor N/i \rfloor - 1 times. Summing over ii:
i=1N(N/i1)=NHNN=O(NlogN),\sum_{i=1}^{N} \left(\lfloor N/i \rfloor - 1\right) = N H_N - N = O(N \log N),

where HN=i=1N1/iH_N = \sum_{i=1}^{N} 1/i is the NN-th harmonic number.

  • Step 2: O(N)O(N) scan.
  • Step 3: The double loop over abundant numbers runs at most (A2)+A=O(A2)\binom{A}{2} + A = O(A^2) iterations. Since the density of abundant numbers is approximately 0.2477, we have A0.2477NA \approx 0.2477 N, giving O(A2)O(0.061N2)O(A^2) \approx O(0.061 N^2). For N=28123N = 28123, this is about 4.8×1074.8 \times 10^7 operations.
  • Step 4: O(N)O(N) scan.

Total: O(NlogN+A2)O(N \log N + A^2). The boolean array and divisor-sum array each require O(N)O(N) space. \square

Answer

4179871\boxed{4179871}

Code

Each problem page includes the exact C++ and Python source files from the local archive.

C++ project_euler/problem_023/solution.cpp
#include <bits/stdc++.h>
using namespace std;

int main() {
    const int N = 28123;

    vector<int> spd(N + 1, 0);
    for (int i = 1; i <= N; i++)
        for (int j = 2 * i; j <= N; j += i)
            spd[j] += i;

    vector<int> abundant;
    for (int i = 1; i <= N; i++)
        if (spd[i] > i)
            abundant.push_back(i);

    vector<bool> is_sum(N + 1, false);
    for (int i = 0; i < (int)abundant.size(); i++)
        for (int j = i; j < (int)abundant.size(); j++) {
            int s = abundant[i] + abundant[j];
            if (s > N) break;
            is_sum[s] = true;
        }

    long long ans = 0;
    for (int i = 1; i <= N; i++)
        if (!is_sum[i])
            ans += i;

    cout << ans << endl;
    return 0;
}