Cody

# Problem 60. The Goldbach Conjecture

Solution 243565

Submitted on 13 May 2013 by Pawel Wojtas
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
%% nList = 28:6:76; for i = 1:length(nList) n = nList(i); [p1,p2] = goldbach(n) assert(isprime(p1) && isprime(p2) && (p1+p2==n)); end

s = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 28 17 18 19 20 21 22 23 24 25 26 27 28 p = Columns 1 through 16 0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 Columns 17 through 28 1 0 1 0 0 0 1 0 0 0 0 0 r = Columns 1 through 16 0 2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 Columns 17 through 28 17 0 19 0 0 0 23 0 0 0 0 0 q = 2 3 5 7 11 13 17 19 23 h = 9 a = 1 a = 2 a = 3 p1 = 5 p2 = 23 a = 4 p1 = 11 p2 = 17 a = 5 p1 = 17 p2 = 11 a = 6 p1 = 17 p2 = 11 s = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 32 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 Columns 33 through 34 33 34 p = Columns 1 through 16 0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 Columns 17 through 32 1 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 Columns 33 through 34 0 0 r = Columns 1 through 16 0 2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 Columns 17 through 32 17 0 19 0 0 0 23 0 0 0 0 0 29 0 31 0 Columns 33 through 34 0 0 q = 2 3 5 7 11 13 17 19 23 29 31 h = 11 a = 1 a = 2 p1 = 3 p2 = 31 p1 = 5 p2 = 29 a = 3 p1 = 11 p2 = 23 a = 4 p1 = 17 p2 = 17 a = 5 p1 = 23 p2 = 11 p1 = 29 p2 = 5 p1 = 29 p2 = 5 s = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 32 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 Columns 33 through 40 33 34 35 36 37 38 39 40 p = Columns 1 through 16 0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 Columns 17 through 32 1 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 Columns 33 through 40 0 0 0 0 1 0 0 0 r = Columns 1 through 16 0 2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 Columns 17 through 32 17 0 19 0 0 0 23 0 0 0 0 0 29 0 31 0 Columns 33 through 40 0 0 0 0 37 0 0 0 q = 2 3 5 7 11 13 17 19 23 29 31 37 h = 12 a = 1 a = 2 p1 = 3 p2 = 37 a = 3 a = 4 p1 = 11 p2 = 29 a = 5 p1 = 17 p2 = 23 a = 6 p1 = 23 p2 = 17 p1 = 29 p2 = 11 a = 7 p1 = 29 p2 = 11 s = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 32 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 Columns 33 through 46 33 34 35 36 37 38 39 40 41 42 43 44 45 46 p = Columns 1 through 16 0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 Columns 17 through 32 1 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 Columns 33 through 46 0 0 0 0 1 0 0 0 1 0 1 0 0 0 r = Columns 1 through 16 0 2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 Columns 17 through 32 17 0 19 0 0 0 23 0 0 0 0 0 29 0 31 0 Columns 33 through 46 0 0 0 0 37 0 0 0 41 0 43 0 0 0 q = 2 3 5 7 11 13 17 19 23 29 31 37 41 43 h = 14 a = 1 a = 2 p1 = 3 p2 = 43 p1 = 5 p2 = 41 a = 3 a = 4 a = 5 p1 = 17 p2 = 29 a = 6 p1 = 23 p2 = 23 p1 = 29 p2 = 17 a = 7 a = 8 p1 = 41 p2 = 5 p1 = 41 p2 = 5 s = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 32 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 Columns 33 through 48 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 Columns 49 through 52 49 50 51 52 p = Columns 1 through 16 0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 Columns 17 through 32 1 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 Columns 33 through 48 0 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0 Columns 49 through 52 0 0 0 0 r = Columns 1 through 16 0 2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 Columns 17 through 32 17 0 19 0 0 0 23 0 0 0 0 0 29 0 31 0 Columns 33 through 48 0 0 0 0 37 0 0 0 41 0 43 0 0 0 47 0 Columns 49 through 52 0 0 0 0 q = 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 h = 15 a = 1 a = 2 a = 3 p1 = 5 p2 = 47 a = 4 p1 = 11 p2 = 41 a = 5 a = 6 a = 7 p1 = 23 p2 = 29 p1 = 29 p2 = 23 a = 8 a = 9 p1 = 41 p2 = 11 a = 10 p1 = 41 p2 = 11 s = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 32 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 Columns 33 through 48 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 Columns 49 through 58 49 50 51 52 53 54 55 56 57 58 p = Columns 1 through 16 0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 Columns 17 through 32 1 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 Columns 33 through 48 0 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0 Columns 49 through 58 0 0 0 0 1 0 0 0 0 0 r = Columns 1 through 16 0 2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 Columns 17 through 32 17 0 19 0 0 0 23 0 0 0 0 0 29 0 31 0 Columns 33 through 48 0 0 0 0 37 0 0 0 41 0 43 0 0 0 47 0 Columns 49 through 58 0 0 0 0 53 0 0 0 0 0 q = 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 h = 16 a = 1 a = 2 a = 3 p1 = 5 p2 = 53 a = 4 p1 = 11 p2 = 47 a = 5 p1 = 17 p2 = 41 a = 6 a = 7 p1 = 29 p2 = 29 a = 8 a = 9 p1 = 41 p2 = 17 a = 10 p1 = 47 p2 = 11 p1 = 47 p2 = 11 s = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 32 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 Columns 33 through 48 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 Columns 49 through 64 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 p = Columns 1 through 16 0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 Columns 17 through 32 1 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 Columns 33 through 48 0 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0 Columns 49 through 64 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 r = Columns 1 through 16 0 2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 Columns 17 through 32 17 0 19 0 0 0 23 0 0 0 0 0 29 0 31 0 Columns 33 through 48 0 0 0 0 37 0 0 0 41 0 43 0 0 0 47 0 Columns 49 through 64 0 0 0 0 53 0 0 0 0 0 59 0 61 0 0 0 q = Columns 1 through 16 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 Columns 17 through 18 59 61 h = 18 a = 1 a = 2 p1 = 3 p2 = 61 p1 = 5 p2 = 59 a = 3 p1 = 11 p2 = 53 a = 4 p1 = 17 p2 = 47 a = 5 p1 = 23 p2 = 41 a = 6 a = 7 a = 8 p1 = 41 p2 = 23 a = 9 p1 = 47 p2 = 17 p1 = 53 p2 = 11 ...

2   Pass
%% nList = [18 20 22 100 102 114 1000 2000 36 3600]; for i = 1:length(nList) n = nList(i); [p1,p2] = goldbach(n) assert(isprime(p1) && isprime(p2) && (p1+p2==n)); end

s = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 18 17 18 p = Columns 1 through 16 0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 Columns 17 through 18 1 0 r = Columns 1 through 16 0 2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 Columns 17 through 18 17 0 q = 2 3 5 7 11 13 17 h = 7 a = 1 a = 2 a = 3 p1 = 5 p2 = 13 p1 = 7 p2 = 11 p1 = 11 p2 = 7 p1 = 13 p2 = 5 p1 = 13 p2 = 5 s = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 20 17 18 19 20 p = Columns 1 through 16 0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 Columns 17 through 20 1 0 1 0 r = Columns 1 through 16 0 2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 Columns 17 through 20 17 0 19 0 q = 2 3 5 7 11 13 17 19 h = 8 a = 1 a = 2 p1 = 3 p2 = 17 a = 3 p1 = 7 p2 = 13 a = 4 p1 = 13 p2 = 7 p1 = 17 p2 = 3 p1 = 17 p2 = 3 s = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 22 17 18 19 20 21 22 p = Columns 1 through 16 0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 Columns 17 through 22 1 0 1 0 0 0 r = Columns 1 through 16 0 2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 Columns 17 through 22 17 0 19 0 0 0 q = 2 3 5 7 11 13 17 19 h = 8 a = 1 a = 2 p1 = 3 p2 = 19 p1 = 5 p2 = 17 a = 3 p1 = 11 p2 = 11 a = 4 p1 = 17 p2 = 5 p1 = 17 p2 = 5 s = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 32 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 Columns 33 through 48 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 Columns 49 through 64 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 Columns 65 through 80 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 Columns 81 through 96 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 Columns 97 through 100 97 98 99 100 p = Columns 1 through 16 0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 Columns 17 through 32 1 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 Columns 33 through 48 0 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0 Columns 49 through 64 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 Columns 65 through 80 0 0 1 0 0 0 1 0 1 0 0 0 0 0 1 0 Columns 81 through 96 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 Columns 97 through 100 1 0 0 0 r = Columns 1 through 16 0 2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 Columns 17 through 32 17 0 19 0 0 0 23 0 0 0 0 0 29 0 31 0 Columns 33 through 48 0 0 0 0 37 0 0 0 41 0 43 0 0 0 47 0 Columns 49 through 64 0 0 0 0 53 0 0 0 0 0 59 0 61 0 0 0 Columns 65 through 80 0 0 67 0 0 0 71 0 73 0 0 0 0 0 79 0 Columns 81 through 96 0 0 83 0 0 0 0 0 89 0 0 0 0 0 0 0 Columns 97 through 100 97 0 0 0 q = Columns 1 through 16 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 Columns 17 through 25 59 61 67 71 73 79 83 89 97 h = 25 a = 1 a = 2 p1 = 3 p2 = 97 a = 3 a = 4 p1 = 11 p2 = 89 a = 5 p1 = 17 p2 = 83 a = 6 a = 7 p1 = 29 p2 = 71 a = 8 a = 9 p1 = 41 p2 = 59 a = 10 p1 = 47 p2 = 53 p1 = 53 p2 = 47 p1 = 59 p2 = 41 a = 11 a = 12 p1 = 71 p2 = 29 a = 13 a = 14 p1 = 83 p2 = 17 p1 = 89 p2 = 11 p1 = 89 p2 = 11 s = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 32 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 Columns 33 through 48 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 Columns 49 through 64 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 Columns 65 through 80 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 Columns 81 through 96 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 Columns 97 through 102 97 98 99 100 101 102 p = Columns 1 through 16 0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 Columns 17 through 32 1 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 Columns 33 through 48 0 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0 Columns 49 through 64 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 Columns 65 through 80 0 0 1 0 0 0 1 0 1 0 0 0 0 0 1 0 Columns 81 through 96 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 Columns 97 through 102 1 0 0 0 1 0 r = Columns 1 through 16 0 2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 Columns 17 through 32 17 0 19 0 0 0 23 0 0 0 0 0 29 0 31 0 Columns 33 through 48 0 0 0 0 37 0 0 0 41 0 43 0 0 0 47 0 Columns 49 through 64 0 0 0 0 53 0 0 0 0 0 59 0 61 0 0 0 Columns 65 through 80 0 0 67 0 0 0 71 0 73 0 0 0 0 0 79 0 Columns 81 through 96 0 0 83 0 0 0 0 0 89 0 0 0 0 0 0 0 Columns 97 through 102 97 0 0 0 101 0 q = Columns 1 through 16 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 Columns 17 through 26 59 61 67 71 73 79 83 89 97 101 h = 26 a = 1 a = 2 a = 3 p1 = 5 p2 = 97 a = 4 a = 5 p1 = 13 p2 = 89 a = 6 p1 = 19 p2 = 83 p1 = 23 p2 = 79 p1 = 29 p2 = 73 p1 = 31 p2 = 71 a = 7 p1 = 41 p2 = 61 p1 = 43 p2 = 59 a = 8 a = 9 p1 = 59 p2 = 43 p1 = 61 p2 = 41 a = 10 p1 = 71 p2 = 31 p1 = 73 p2 = 29 p1 = 79 p2 = 23 p1 = 83 p2 = 19 p1 = 89 p2 = 13 p1 = 97 p2 = 5 p1 = 97 p2 = 5 s = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 32 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 Columns 33 through 48 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 Columns 49 through 64 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 Columns 65 through 80 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 Columns 81 through 96 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 Columns 97 through 112 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 Columns 113 through 114 113 114 p = Columns 1 through 16 0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 Columns 17 through 32 1 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 Columns 33 through 48 0 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0 Columns 49 through 64 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 Columns 65 through 80 0 0 1 0 0 0 1 0 1 0 0 0 0 0 1 0 Columns 81 through 96 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 Columns 97 through 112 1 0 0 0 ...