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?

 

解決問題: 

		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;
			}
			}
		}
		 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章