All Euler problems
Project Euler

Goldbach's Other Conjecture

It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square. It turns out that the conjecture was false. What is the smallest odd c...

Source sync Apr 19, 2026
Problem #0046
Level Level 01
Solved By 68,773
Languages C++, Python
Answer 5777
Length 530 words
number_theorybrute_forcelinear_algebra

Problem Statement

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

It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square. \begin {align*} 9 = 7 + 2 \times 1^2\\ 15 = 7 + 2 \times 2^2\\ 21 = 3 + 2 \times 3^2\\ 25 = 7 + 2 \times 3^2\\ 27 = 19 + 2 \times 2^2\\ 33 = 31 + 2 \times 1^2 \end {align*}

It turns out that the conjecture was false.

What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?

Problem 46: Goldbach’s Other Conjecture

Mathematical Development

Formal Development

Definition 1 (Goldbach Representability). An odd integer n>1n > 1 is Goldbach-representable if there exist a prime pp and an integer k1k \geq 1 such that n=p+2k2n = p + 2k^2. Let G\mathcal{G} denote the set of all Goldbach-representable odd integers.

Definition 2 (Odd Composites). Let Codd={nZ:n>1, n is odd, n is not prime}\mathcal{C}_{\mathrm{odd}} = \{n \in \mathbb{Z} : n > 1,\ n \text{ is odd},\ n \text{ is not prime}\}.

Goldbach’s other conjecture asserts that CoddG\mathcal{C}_{\mathrm{odd}} \subseteq \mathcal{G}. We seek min(CoddG)\min(\mathcal{C}_{\mathrm{odd}} \setminus \mathcal{G}).

Lemma 1 (Bound on the square index). Let nCoddn \in \mathcal{C}_{\mathrm{odd}}. If nGn \in \mathcal{G}, then there exists a witness (p,k)(p, k) with 1kK(n)1 \leq k \leq K(n), where K(n):=(n2)/2K(n) := \lfloor\sqrt{(n - 2)/2}\rfloor.

Proof. Suppose n=p+2k2n = p + 2k^2 with pp prime and k1k \geq 1. Since p2p \geq 2, we have 2k2=npn22k^2 = n - p \leq n - 2, whence k2(n2)/2k^2 \leq (n - 2)/2. Therefore k(n2)/2=K(n)k \leq \lfloor\sqrt{(n-2)/2}\rfloor = K(n). \square

Lemma 2 (Parity of the remainder). For any odd integer nn and any integer k1k \geq 1, the value rk:=n2k2r_k := n - 2k^2 is odd.

Proof. Since nn is odd and 2k22k^2 is even, their difference is odd. \square

Lemma 3 (Reduction to primality testing). An odd composite nn belongs to G\mathcal{G} if and only if there exists k{1,2,,K(n)}k \in \{1, 2, \ldots, K(n)\} such that n2k2n - 2k^2 is prime.

Proof. (\Rightarrow) By definition, n=p+2k2n = p + 2k^2 with pp prime and k1k \geq 1. By Lemma 1, kK(n)k \leq K(n), so p=n2k2p = n - 2k^2 is prime for some kk in the stated range.

(\Leftarrow) If n2k2n - 2k^2 is prime for some 1kK(n)1 \leq k \leq K(n), set p=n2k2p = n - 2k^2. Then n=p+2k2n = p + 2k^2 with pp prime and k1k \geq 1, so nGn \in \mathcal{G}. \square

Theorem 1. The smallest odd composite number that is not Goldbach-representable is 57775777. That is, min(CoddG)=5777\min(\mathcal{C}_{\mathrm{odd}} \setminus \mathcal{G}) = 5777.

Proof. The proof proceeds in three parts.

Part 1 (5777 is an odd composite). We verify 5777=53×1095777 = 53 \times 109, where 5353 and 109109 are both prime. Hence 57775777 is composite. Since 5353 and 109109 are both odd, their product is odd. Thus 5777Codd5777 \in \mathcal{C}_{\mathrm{odd}}.

Part 2 (5777 is not Goldbach-representable). By Lemma 3, it suffices to show that 57772k25777 - 2k^2 is composite for every k{1,2,,K(5777)}k \in \{1, 2, \ldots, K(5777)\}. We compute K(5777)=(57772)/2=2887.5=53K(5777) = \lfloor\sqrt{(5777 - 2)/2}\rfloor = \lfloor\sqrt{2887.5}\rfloor = 53. For each k{1,,53}k \in \{1, \ldots, 53\}, define rk=57772k2r_k = 5777 - 2k^2. By Lemma 2, each rkr_k is odd, so the question reduces to whether any rkr_k is an odd prime. Exhaustive computation confirms that none of r1,r2,,r53r_1, r_2, \ldots, r_{53} is prime. Representative values:

kkrk=57772k2r_k = 5777 - 2k^2Factorization
157753×52×7×113 \times 5^2 \times 7 \times 11
257693×19233 \times 1923
3575913×44313 \times 443
\vdots\vdotscomposite
531593×533 \times 53

Since no witness exists, 5777G5777 \notin \mathcal{G}.

Part 3 (Minimality). By exhaustive computation (via sieve-assisted primality lookup), every odd composite nn with 9n<57779 \leq n < 5777 satisfies nGn \in \mathcal{G}: for each such nn, at least one k{1,,K(n)}k \in \{1, \ldots, K(n)\} yields a prime remainder n2k2n - 2k^2.

Combining Parts 1—3, 5777=min(CoddG)5777 = \min(\mathcal{C}_{\mathrm{odd}} \setminus \mathcal{G}). \square

Editorial

We first build a primality table up to a search limit using the Sieve of Eratosthenes. Then we inspect odd composite integers in increasing order, and for each such nn we test all values of kk with 2k2<n2k^2 < n to see whether the remainder n2k2n - 2k^2 is prime. The first odd composite for which no such witness exists is the smallest counterexample to Goldbach’s other conjecture.

Pseudocode

Algorithm: Smallest Odd Composite Violating Goldbach's Other Conjecture
Require: A prime table on a search interval.
Ensure: The smallest odd composite n that cannot be written as p + 2k^2.
1: Build a primality table on the search interval.
2: For each odd composite n in increasing order do:
3:     For each k ≥ 1 with 2k^2 < n, test whether n - 2k^2 is prime.
4:     If no such k succeeds, return n.

Complexity Analysis

Proposition (Time complexity). Let N=5777N = 5777 denote the answer. The algorithm runs in O(NN+NloglogN)O(N\sqrt{N} + N\log\log N) time.

Proof. The sieve of Eratosthenes on [0,L][0, L] with L=O(N)L = O(N) runs in O(LloglogL)=O(NloglogN)O(L \log \log L) = O(N \log \log N) time (classical result). The main loop iterates over at most (N9)/2+1=O(N)(N - 9)/2 + 1 = O(N) odd integers. For each odd composite nn, the inner loop runs at most K(n)=O(n)=O(N)K(n) = O(\sqrt{n}) = O(\sqrt{N}) iterations, each performing an O(1)O(1) sieve lookup. The total work in the main loop is therefore nNO(n)=O(NN)\sum_{n \leq N} O(\sqrt{n}) = O(N\sqrt{N}). Since NNN\sqrt{N} dominates NloglogNN \log\log N, the overall complexity is O(NN)O(N\sqrt{N}). With N=5777N = 5777, this yields approximately 4.4×1054.4 \times 10^5 operations. \square

Proposition (Space complexity). The algorithm uses O(N)O(N) space.

Proof. The sieve array of size L+1=O(N)L + 1 = O(N) is the only data structure. All other variables are O(1)O(1). \square

Answer

5777\boxed{5777}

Code

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

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

int main() {
    const int LIMIT = 10000;
    vector<bool> is_prime(LIMIT, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i * i < LIMIT; i++)
        if (is_prime[i])
            for (int j = i * i; j < LIMIT; j += i)
                is_prime[j] = false;

    for (int n = 9; n < LIMIT; n += 2) {
        if (is_prime[n]) continue;
        bool found = false;
        for (int k = 1; 2 * k * k < n; k++) {
            if (is_prime[n - 2 * k * k]) {
                found = true;
                break;
            }
        }
        if (!found) {
            cout << n << endl;
            return 0;
        }
    }
    return 0;
}