0
点赞
收藏
分享

微信扫一扫

Problem 46 Goldbach's other conjecture (暴力...)


Goldbach's other conjecture

Problem 46

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×12
15 = 7 + 2×22
21 = 3 + 2×32
25 = 7 + 2×32
27 = 19 + 2×22
33 = 31 + 2×12

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?

Answer:

5777

Completed on Mon, 31 Oct 2016, 05:11


代码:


#include<bits/stdc++.h>
using namespace std;
int isprim(int n) //素数判断
{
for(int i=2; i*i<=n; i++)
{
if(n%i==0) return 0;
}
return 1;
}

int judge(long long n)
{
int i=1;
long long t;
while((t=(n-2*(i*i)))>0)
{
if(isprim(t)) return 1;
i++;
}
return 0;
}

int main()
{
for(long long i=1001; i<100000000; i+=2)
{
if(!isprim(i) && !judge(i)) //不是素数
{
printf("%lld\n",i);
break;
}
}
return 0;
}





举报

相关推荐

0 条评论