Cody

# Problem 60. The Goldbach Conjecture

Solution 324728

Submitted on 27 Sep 2013 by Zikobrelli
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

A = 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 A = 2 3 5 7 11 13 17 19 23 p1 = 2 3 5 7 11 13 17 19 23 p2 = 26 25 23 21 17 15 11 9 5 AA = 3 5 7 9 p2 = 23 17 11 5 p1 = 5 11 17 23 p2 = 23 p1 = 5 p1 = 5 p2 = 23 A = 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 A = 2 3 5 7 11 13 17 19 23 29 31 p1 = 2 3 5 7 11 13 17 19 23 29 31 p2 = 32 31 29 27 23 21 17 15 11 5 3 AA = 2 3 5 7 9 10 11 p2 = 31 29 23 17 11 5 3 p1 = 3 5 11 17 23 29 31 p2 = 31 p1 = 3 p1 = 3 p2 = 31 A = 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 A = 2 3 5 7 11 13 17 19 23 29 31 37 p1 = 2 3 5 7 11 13 17 19 23 29 31 37 p2 = 38 37 35 33 29 27 23 21 17 11 9 3 AA = 2 5 7 9 10 12 p2 = 37 29 23 17 11 3 p1 = 3 11 17 23 29 37 p2 = 37 p1 = 3 p1 = 3 p2 = 37 A = 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 A = 2 3 5 7 11 13 17 19 23 29 31 37 41 43 p1 = 2 3 5 7 11 13 17 19 23 29 31 37 41 43 p2 = 44 43 41 39 35 33 29 27 23 17 15 9 5 3 AA = 2 3 7 9 10 13 14 p2 = 43 41 29 23 17 5 3 p1 = 3 5 17 23 29 41 43 p2 = 43 p1 = 3 p1 = 3 p2 = 43 A = 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 A = 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 p1 = 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 p2 = 50 49 47 45 41 39 35 33 29 23 21 15 11 9 5 AA = 3 5 9 10 13 15 p2 = 47 41 29 23 11 5 p1 = 5 11 23 29 41 47 p2 = 47 p1 = 5 p1 = 5 p2 = 47 A = 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 A = 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 p1 = 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 p2 = 56 55 53 51 47 45 41 39 35 29 27 21 17 15 11 5 AA = 3 5 7 10 13 15 16 p2 = 53 47 41 29 17 11 5 p1 = 5 11 17 29 41 47 53 p2 = 53 p1 = 5 p1 = 5 p2 = 53 A = 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 A = 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 p1 = 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 p2 = Columns 1 through 16 62 61 59 57 53 51 47 45 41 35 33 27 23 21 17 11 Columns 17 through 18 5 3 AA = 2 3 5 7 9 13 15 16 17 18 p2 = 61 59 53 47 41 23 17 11 5 3 p1 = 3 5 11 17 23 41 47 53 59 61 p2 = 61 p1 = 3 p1 = 3 p2 = 61 A = 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 70 0 0 1 0 0 0 A = Columns 1 through 16 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 Columns 17 through 19 59 61 67 p1 = Columns 1 through 16 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 Columns 17 through 19 59 61 67 p2 = Columns 1 through 16 68 67 65 63 59 57 53 51 47 41 39 33 29 27 23 17 Columns 17 through 19 11 9 3 AA = 2 5 7 9 10 13 15 16 17 19 p2 = 67 59 53 47 41 29 23 17 11 3 p1 = 3 11 17 23 29 41 47 53 59 67 p2 = 67 p1 = 3 p1 = 3 p2 = 67 A = 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 76 0 0 1 0 0 0 1 0 1 0 0 0 A = Columns 1 through 16 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 Columns 17 through 21 59 61 67 71 73 p1 = Columns 1 through 16 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 Columns 17 through 21 59 61 67 71 73 p2 = Columns 1 through 16 74 73 71 69 65 63 59 57 53 47 45 39 35 33 29 23 Columns 17 through 21 17 15 9 5 3 AA = 2 3 7 9 10 15 16 17 20 21 p2 = 73 71 59 53 47 29 23 17 5 3 p1 = 3 5 17 23 29 47 53 59 71 73 p2 = 73 p1 = 3 p1 = 3 p2 = 73

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

A = 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 A = 2 3 5 7 11 13 17 p1 = 2 3 5 7 11 13 17 p2 = 16 15 13 11 7 5 1 AA = 3 4 5 6 p2 = 13 11 7 5 p1 = 5 7 11 13 p2 = 13 p1 = 5 p1 = 5 p2 = 13 A = 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 A = 2 3 5 7 11 13 17 19 p1 = 2 3 5 7 11 13 17 19 p2 = 18 17 15 13 9 7 3 1 AA = 2 4 6 7 p2 = 17 13 7 3 p1 = 3 7 13 17 p2 = 17 p1 = 3 p1 = 3 p2 = 17 A = 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 A = 2 3 5 7 11 13 17 19 p1 = 2 3 5 7 11 13 17 19 p2 = 20 19 17 15 11 9 5 3 AA = 2 3 5 7 8 p2 = 19 17 11 5 3 p1 = 3 5 11 17 19 p2 = 19 p1 = 3 p1 = 3 p2 = 19 A = 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 A = 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 p1 = 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 p2 = Columns 1 through 16 98 97 95 93 89 87 83 81 77 71 69 63 59 57 53 47 Columns 17 through 25 41 39 33 29 27 21 17 11 3 AA = 2 5 7 10 13 15 16 17 20 23 24 25 p2 = 97 89 83 71 59 53 47 41 29 17 11 3 p1 = 3 11 17 29 41 47 53 59 71 83 89 97 p2 = 97 p1 = 3 p1 = 3 p2 = 97 A = 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 A = 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 p1 = 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 p2 = Columns 1 through 16 100 99 97 95 91 89 85 83 79 73 71 65 61 59 55 49 Columns 17 through 26 43 41 35 31 29 23 19 13 5 1 AA = 3 6 8 9 10 11 13 14 17 18 20 21 22 23 24 25 p2 = 97 89 83 79 73 71 61 59 43 41 31 29 23 19 13 5 p1 = 5 13 19 23 29 31 41 43 59 61 71 73 79 83 89 97 p2 = 97 p1 = 5 p1 = 5 p2 = 97 A = 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 1 0 1 0 0 0 1 0 1 0 0 0 Columns 113 through 114 1 0 A = Columns 1 through 16 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 Columns 17 through 30 59 61 67 71 73 79 83 89 97 101 103 107 109 113 p1 = Columns 1 through 16 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 Columns 17 through 30 59 61 67 71 73 79 83 89 97 101 103 107 109 113 p2 = Columns 1 through 16 112 111 109 107 103 101 97 95 91 85 83 77 73 71 67 61 Columns 17 through 30 55 53 47 43 41 35 31 25 17 13 11 7 5 1 AA = Columns 1 through 16 3 4 5 6 7 11 13 14 15 16 18 19 20 21 23 25 Columns 17 through 20 26 27 28 29 p2 = Columns 1 through 16 109 107 103 101 97 83 73 71 67 61 53 47 43 41 31 17 Columns 17 through 20 13 11 7 5 p1 = Columns 1 through 16 5 7 11 13 17 31 41 43 47 53 61 67 71 73 83 97 Columns 17 through 20 101 103 107 109 p2 = 109 p1 = 5 p1 = 5 p2 = 109 A = 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 1 0 1 0 0 0 1 0 1 0 0 0 Columns 113 through 128 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 Columns 129 through 144 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 Columns 145 through 160 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 Columns 161 through 176 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 Columns 177 through 192 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 Columns 193 through 208 1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 Columns 209 through 224 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 Columns 225 through 240 0 0 1 0 1 0 0 0 1 0 0 0 0 0 1 0 Columns 241 through 256 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 Columns 257 through 272 1 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 Columns 273 through 288 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 Columns 289 through 304 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 Columns 305 through 320 0 0 1 0 0 0 1 0 1 0 0 0 1 0 0 0 Columns 321 through 336 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 Columns 337 through 352 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 Columns 353 through 368 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 Columns 369 through 384 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 Columns 385 through 400 0 ...

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!