It is proposed by Christian Goldbach, every odd composite number can be written as the sum of a prime and twice a squ Is.
9 = 7 + 2x12
7 + 2x22
3 + 2x32
7 + 2x32
+ 2x22
= + 2x12
It turns out that the conjecture is false.
What's the smallest odd composite that cannot be written as the sum of a prime and twice a square?
#include <iostream>using namespace Std;bool isprime[1000010];bool Gold (int n) {for (int i = 2; i < n; i++) {if (IsP Rime[i] = = true) {int tmp = N-i;//cout << i << "" << tmp << endl;if (tmp% 2 = = 0) {int k = sqrt ( TMP/2); if (k*k = = TMP/2) return true;}}} return false;} int main () {memset (IsPrime, True, sizeof (IsPrime)), for (int i = 2; I <= 1010; i++) {if (Isprime[i]) {(int j = 2; J*i & Lt 1000010; J + +) {Isprime[i*j] = false;}}} int a = Gold (n), for (int i = 2; I <= 1000000; i++) {if (isprime[i] = False && I 2 = = 1) {if (!gold (i)) {cout << i << Endl;break;}}} System ("pause"); return 0;}
Project Euler:problem Goldbach ' s other conjecture