Christian Goldbach 提出每個奇合數都可以寫作一個質數與一個平方數的二倍之和:
9 = 7 + 212
15 = 7 + 222
21 = 3 + 232
25 = 7 + 232
27 = 19 + 222
33 = 31 + 212
但是這個推測是錯誤的。
最小的不能寫作一個質數與一個平方數的二倍之和的奇合數是多少?
public class Problem46
{
public static void main(String[] args)
{
long start = System.currentTimeMillis();
System.out.print("answer: ");
howmany();
long end = System.currentTimeMillis();
System.out.print("time: ");
System.out.println(end - start);
}
static void howmany()
{
l1 : for (int i = 35; ; i += 2)
{
if (iszhishu(i))
{
continue;
}
for (int j = 1; ; j++)
{
int t = 2 * j * j;
if (t > i)
{
break;
}
if (iszhishu(i - t))
{
continue l1;
}
}
System.out.println(i);
break;
}
}
static boolean iszhishu(int n)
{
for (int i = 2; i <= Math.sqrt(n); i++)
{
if (n % i == 0)
{
return false;
}
}
return true;
}
}
answer: 5777
time: 8