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 + 212
15 = 7 + 222
21 = 3 + 232
25 = 7 + 232
27 = 19 + 222
33 = 31 + 212
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 提出每个奇合数都可以写作一个质数与一个平方数的二倍之和:
9 = 7 + 212
15 = 7 + 222
21 = 3 + 232
25 = 7 + 232
27 = 19 + 222
33 = 31 + 212
但是这个推测是错误的。
最小的不能写作一个质数与一个平方数的二倍之和的奇合数是多少?
//(Problem 46)Goldbach's other conjecture
// Completed on Fri, 26 Jul 2013, 16:58
// Language: C11
//
// 版权所有(C)acutus (mail: acutus@126.com)
// 博客地址:http://www.cnblogs.com/acutus/
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<stdbool.h> bool issquare(int n) //判断一个自然数是否为一个平方数
{
if(ceil(sqrt(n))*ceil(sqrt(n))==n) return true;
else return false;
} bool isprim(int n) //素数判断
{
for(int i=; i*i<=n; i++)
{
if(n%i==) return false;
}
return true;
} bool judge(long long n)
{
int i=;
long long t;
while((t=(n-*(i*i)))>)
{
if(isprim(t)) return true;
i++;
}
return false;
} int main()
{
for(long long i=; i<; i=i+)
{
if(!isprim(i) && !judge(i))
{
printf("%lld\n",i);
break;
}
}
return ;
}
Answer:
|
5777 |