Project Euler:problem Goldbach ' s other conjecture

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.