Cody

Problem 60. The Goldbach Conjecture

Solution 1081510

Submitted on 14 Dec 2016 by Sunke
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

gef = 1×9 logical array 0 0 0 0 0 0 0 0 0 gef = 1×9 logical array 0 0 0 0 0 0 0 0 0 gef = 1×9 logical array 0 0 0 0 0 0 0 0 1 gef = 1×9 logical array 0 0 0 0 0 0 0 0 0 gef = 1×9 logical array 0 0 0 0 0 0 1 0 0 gef = 1×9 logical array 0 0 0 0 0 0 0 0 0 gef = 1×9 logical array 0 0 0 0 1 0 0 0 0 gef = 1×9 logical array 0 0 0 0 0 0 0 0 0 gef = 1×9 logical array 0 0 1 0 0 0 0 0 0 p1 = 23 p2 = 5 gef = 1×11 logical array 0 0 0 0 0 0 0 0 0 0 0 gef = 1×11 logical array 0 0 0 0 0 0 0 0 0 0 1 gef = 1×11 logical array 0 0 0 0 0 0 0 0 0 1 0 gef = 1×11 logical array 0 0 0 0 0 0 0 0 0 0 0 gef = 1×11 logical array 0 0 0 0 0 0 0 0 1 0 0 gef = 1×11 logical array 0 0 0 0 0 0 0 0 0 0 0 gef = 1×11 logical array 0 0 0 0 0 0 1 0 0 0 0 gef = 1×11 logical array 0 0 0 0 0 0 0 0 0 0 0 gef = 1×11 logical array 0 0 0 0 1 0 0 0 0 0 0 gef = 1×11 logical array 0 0 1 0 0 0 0 0 0 0 0 gef = 1×11 logical array 0 1 0 0 0 0 0 0 0 0 0 p1 = 31 p2 = 3 gef = 1×12 logical array 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×12 logical array 0 0 0 0 0 0 0 0 0 0 0 1 gef = 1×12 logical array 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×12 logical array 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×12 logical array 0 0 0 0 0 0 0 0 0 1 0 0 gef = 1×12 logical array 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×12 logical array 0 0 0 0 0 0 0 0 1 0 0 0 gef = 1×12 logical array 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×12 logical array 0 0 0 0 0 0 1 0 0 0 0 0 gef = 1×12 logical array 0 0 0 0 1 0 0 0 0 0 0 0 gef = 1×12 logical array 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×12 logical array 0 1 0 0 0 0 0 0 0 0 0 0 p1 = 37 p2 = 3 gef = 1×14 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×14 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 1 gef = 1×14 logical array 0 0 0 0 0 0 0 0 0 0 0 0 1 0 gef = 1×14 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×14 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×14 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×14 logical array 0 0 0 0 0 0 0 0 0 1 0 0 0 0 gef = 1×14 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×14 logical array 0 0 0 0 0 0 0 0 1 0 0 0 0 0 gef = 1×14 logical array 0 0 0 0 0 0 1 0 0 0 0 0 0 0 gef = 1×14 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×14 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×14 logical array 0 0 1 0 0 0 0 0 0 0 0 0 0 0 gef = 1×14 logical array 0 1 0 0 0 0 0 0 0 0 0 0 0 0 p1 = 43 p2 = 3 gef = 1×15 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×15 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×15 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 gef = 1×15 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×15 logical array 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 gef = 1×15 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×15 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×15 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×15 logical array 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 gef = 1×15 logical array 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 gef = 1×15 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×15 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×15 logical array 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 gef = 1×15 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×15 logical array 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 p1 = 47 p2 = 5 gef = 1×16 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×16 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×16 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 gef = 1×16 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×16 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 gef = 1×16 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×16 logical array 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 gef = 1×16 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×16 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×16 logical array 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 gef = 1×16 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×16 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×16 logical array 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 gef = 1×16 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×16 logical array 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 gef = 1×16 logical array 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 p1 = 53 p2 = 5 gef = 1×18 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×18 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 gef = 1×18 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 gef = 1×18 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×18 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 gef = 1×18 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×18 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 gef = 1×18 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×18 logical array 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 gef = 1×18 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×18 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×18 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×18 logical array 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 gef = 1×18 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×18 logical array 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 gef = 1×18 logical array 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×18 logical array 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×18 logical array 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 p1 = 61 p2 = 3 gef = 1×19 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×19 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 gef = 1×19 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×19 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×19 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 gef = 1×19 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×19 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 gef = 1×19 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×19 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 gef = 1×19 logical array 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 gef = 1×19 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×19 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gef = 1×19 logical array 0 0 0 0 0 0 0 0 0 1 0 ...

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

gef = 1×7 logical array 0 0 0 0 0 0 0 gef = 1×7 logical array 0 0 0 0 0 0 0 gef = 1×7 logical array 0 0 0 0 0 1 0 gef = 1×7 logical array 0 0 0 0 1 0 0 gef = 1×7 logical array 0 0 0 1 0 0 0 gef = 1×7 logical array 0 0 1 0 0 0 0 gef = 1×7 logical array 0 0 0 0 0 0 0 p1 = 13 p2 = 5 gef = 1×8 logical array 0 0 0 0 0 0 0 0 gef = 1×8 logical array 0 0 0 0 0 0 1 0 gef = 1×8 logical array 0 0 0 0 0 0 0 0 gef = 1×8 logical array 0 0 0 0 0 1 0 0 gef = 1×8 logical array 0 0 0 0 0 0 0 0 gef = 1×8 logical array 0 0 0 1 0 0 0 0 gef = 1×8 logical array 0 1 0 0 0 0 0 0 gef = 1×8 logical array 0 0 0 0 0 0 0 0 p1 = 17 p2 = 3 gef = 1×8 logical array 0 0 0 0 0 0 0 0 gef = 1×8 logical array 0 0 0 0 0 0 0 1 gef = 1×8 logical array 0 0 0 0 0 0 1 0 gef = 1×8 logical array 0 0 0 0 0 0 0 0 gef = 1×8 logical array 0 0 0 0 1 0 0 0 gef = 1×8 logical array 0 0 0 0 0 0 0 0 gef = 1×8 logical array 0 0 1 0 0 0 0 0 gef = 1×8 logical array 0 1 0 0 0 0 0 0 p1 = 19 p2 = 3 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Column 25 1 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Column 25 0 gef = 1×25 logical array Columns 1 through 24 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Column 25 0 p1 = 97 p2 = 3 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 25 through 26 1 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 25 through 26 0 0 gef = 1×26 logical array Columns 1 through 24 0 0 0 0 ...

Suggested Problems

More from this Author95

Community Treasure Hunt

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

Start Hunting!