Problem:
Christian Goldbach (1690–1764) conjectured in 1742 that every even number greater than 2
is the sum of two primes. Write a program that tests the Goldbach conjecture for all even
numbers less than 100. Use the Primes class from Problem 2.22. Your first 10 lines of output
should look like this:
is the sum of two primes. Write a program that tests the Goldbach conjecture for all even
numbers less than 100. Use the Primes class from Problem 2.22. Your first 10 lines of output
should look like this:
Output:
4 = 2+2
6 = 3+3
8 = 3+5
10 = 3+7 = 5+5
12 = 5+7
14 = 3+11 = 7+7
16 = 3+13 = 5+11
18 = 5+13 = 7+11
20 = 3+17 = 7+13
22 = 3+19 = 5+17 = 11+11
6 = 3+3
8 = 3+5
10 = 3+7 = 5+5
12 = 5+7
14 = 3+11 = 7+7
16 = 3+13 = 5+11
18 = 5+13 = 7+11
20 = 3+17 = 7+13
22 = 3+19 = 5+17 = 11+11
Solution:
public class TestGoldbach { public static void main(String[] args) { Primes.setSize(1000); System.out.println("4 = 2+2"); for (int n = 6; n < 100; n += 2) { System.out.print(n); for (int p = 3; p <= n/2; p += 2) { if (Primes.isPrime(p) && Primes.isPrime(n-p)) { System.out.print(" = "+p+"+"+(n-p)); } } System.out.println(); } } }
ultrasonic liposuction Korea's #1 Liposculpture Clinic. Lydian plastic surgery is the home of VIP patients. Celebrities, Influencers and Diplomats all know and trust Doctor An and Lydian plastic surgery clinic to provide detailed results.
ReplyDeletetummy tuck liposuction Korea's #1 Liposculpture Clinic. Lydian plastic surgery is the home of VIP patients. Celebrities, Influencers and Diplomats all know and trust Doctor An and Lydian plastic surgery clinic to provide detailed results.
ReplyDelete