# [Goldbach’s other conjecture](https://projecteuler.net/problem=46)
<blockquote>
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?
</blockquote>

Starting with $9$, check each odd composite number $n$ to see if it is the sum of a prime and twice a square. Only check primes less than $n$ and integers not greater than $\sqrt{n / 2}$. If $n$ is not such a sum, we are done.


```julia
using Primes

f(n) = any(n == p + 2 * b^2 for p in primes(n), b in 1:isqrt(n÷2))
function g(n)
    n += 2
    while isprime(n) n += 2; end
    n
end

n = 9
while f(n)
    n = g(n)
end
n
```




    5777



2462f7198cf721b3475e97a03947579f8511dc61
ipynb
Jupyter Notebook
work/problem046.ipynb
robireton/math-capstone
71f4217aef2e11a7e4e63cec38392a185c72598b
MIT
work/problem046.ipynb
robireton/math-capstone
71f4217aef2e11a7e4e63cec38392a185c72598b
MIT
work/problem046.ipynb
robireton/math-capstone
71f4217aef2e11a7e4e63cec38392a185c72598b
MIT
Qwen/Qwen-72B
1. YES
2. YES