Original

It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square.

9 = 7 + 2×1^2
15 = 7 + 2×2^2
21 = 3 + 2×3^2
25 = 7 + 2×3^2
27 = 19 + 2×2^2
33 = 31 + 2×1^2
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?

和訳

Christian Goldbachは全ての奇合成数は平方数の2倍と素数の和で表せると予想した.

  • 9 = 7 + 2×1^2
  • 15 = 7 + 2×2^2
  • 21 = 3 + 2×3^2
  • 25 = 7 + 2×3^2
  • 27 = 19 + 2×2^2
  • 33 = 31 + 2×1^2

後に, この予想は誤りであることが分かった.

平方数の2倍と素数の和で表せない最小の奇合成数を答えよ.

当てにならないソースコード(C#)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;

namespace ProjectEuler {
    class Problem46 : Problem{

        public Problem46() {
            int answer = 0;
            bool found = true;
            Primes p = new Primes();
            for (int i = 9; found; i += 2) {
                if (!IsOddComposite(i))
                    continue;
                found = false;
                for (int j = 1; 2 * j * j < i && !found; j++) {
                    if (p.IsPrime(i - 2 * j * j))
                        found = true;
                }
                if (!found)
                    answer = i;
            }
            Console.WriteLine(">" + answer);
        }
        bool IsOddComposite(int n) {
            int root = (int)Math.Sqrt(n);
            for (long i = 3; i<=root;i+=2 )
                if (n % i == 0)
                    return true;
            return false;
        }
    }
}