问题描述:
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?
解决问题:
int i =33; boolean ok = true; for(;ok;){ i=i+2; int j; if(IsPrime(i)){ for( j=1; 2*j*j<i; j++){ if(IsPrime(i-2*j*j)){ break; } } if(2*j*j>=i){ System.out.println("j:"+j+".i:"+i); ok = false; } } }