Cody

# Problem 60. The Goldbach Conjecture

Solution 140945

Submitted on 21 Sep 2012 by Lone Christoffersen
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

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

p1 = 2 3 5 7 11 13 17 p2 = 16 15 13 11 7 5 1 i = 3 4 5 6 p1 = 5 p2 = 13 p1 = 5 p2 = 13 p1 = 2 3 5 7 11 13 17 19 p2 = 18 17 15 13 9 7 3 1 i = 2 4 6 7 p1 = 3 p2 = 17 p1 = 3 p2 = 17 p1 = 2 3 5 7 11 13 17 19 p2 = 20 19 17 15 11 9 5 3 i = 2 3 5 7 8 p1 = 3 p2 = 19 p1 = 3 p2 = 19 p1 = Columns 1 through 10 2 3 5 7 11 13 17 19 23 29 Columns 11 through 20 31 37 41 43 47 53 59 61 67 71 Columns 21 through 25 73 79 83 89 97 p2 = Columns 1 through 10 98 97 95 93 89 87 83 81 77 71 Columns 11 through 20 69 63 59 57 53 47 41 39 33 29 Columns 21 through 25 27 21 17 11 3 i = Columns 1 through 10 2 5 7 10 13 15 16 17 20 23 Columns 11 through 12 24 25 p1 = 3 p2 = 97 p1 = 3 p2 = 97 p1 = Columns 1 through 10 2 3 5 7 11 13 17 19 23 29 Columns 11 through 20 31 37 41 43 47 53 59 61 67 71 Columns 21 through 26 73 79 83 89 97 101 p2 = Columns 1 through 10 100 99 97 95 91 89 85 83 79 73 Columns 11 through 20 71 65 61 59 55 49 43 41 35 31 Columns 21 through 26 29 23 19 13 5 1 i = Columns 1 through 10 3 6 8 9 10 11 13 14 17 18 Columns 11 through 16 20 21 22 23 24 25 p1 = 5 p2 = 97 p1 = 5 p2 = 97 p1 = Columns 1 through 10 2 3 5 7 11 13 17 19 23 29 Columns 11 through 20 31 37 41 43 47 53 59 61 67 71 Columns 21 through 30 73 79 83 89 97 101 103 107 109 113 p2 = Columns 1 through 10 112 111 109 107 103 101 97 95 91 85 Columns 11 through 20 83 77 73 71 67 61 55 53 47 43 Columns 21 through 30 41 35 31 25 17 13 11 7 5 1 i = Columns 1 through 10 3 4 5 6 7 11 13 14 15 16 Columns 11 through 20 18 19 20 21 23 25 26 27 28 29 p1 = 5 p2 = 109 p1 = 5 p2 = 109 p1 = Columns 1 through 10 2 3 5 7 11 13 17 19 23 29 Columns 11 through 20 31 37 41 43 47 53 59 61 67 71 Columns 21 through 30 73 79 83 89 97 101 103 107 109 113 Columns 31 through 40 127 131 137 139 149 151 157 163 167 173 Columns 41 through 50 179 181 191 193 197 199 211 223 227 229 Columns 51 through 60 233 239 241 251 257 263 269 271 277 281 Columns 61 through 70 283 293 307 311 313 317 331 337 347 349 Columns 71 through 80 353 359 367 373 379 383 389 397 401 409 Columns 81 through 90 419 421 431 433 439 443 449 457 461 463 Columns 91 through 100 467 479 487 491 499 503 509 521 523 541 Columns 101 through 110 547 557 563 569 571 577 587 593 599 601 Columns 111 through 120 607 613 617 619 631 641 643 647 653 659 Columns 121 through 130 661 673 677 683 691 701 709 719 727 733 Columns 131 through 140 739 743 751 757 761 769 773 787 797 809 Columns 141 through 150 811 821 823 827 829 839 853 857 859 863 Columns 151 through 160 877 881 883 887 907 911 919 929 937 941 Columns 161 through 168 947 953 967 971 977 983 991 997 p2 = Columns 1 through 10 998 997 995 993 989 987 983 981 977 971 Columns 11 through 20 969 963 959 957 953 947 941 939 933 929 Columns 21 through 30 927 921 917 911 903 899 897 893 891 887 Columns 31 through 40 873 869 863 861 851 849 843 837 833 827 Columns 41 through 50 821 819 809 807 803 801 789 777 773 771 Columns 51 through 60 767 761 759 749 743 737 731 729 723 719 Columns 61 through 70 717 707 693 689 687 683 669 663 653 651 Columns 71 through 80 647 641 633 627 621 617 611 603 599 591 Columns 81 through 90 581 579 569 567 561 557 551 543 539 537 Columns 91 through 100 533 521 513 509 501 497 491 479 477 459 Columns 101 through 110 453 443 437 431 429 423 413 407 401 399 Columns 111 through 120 393 387 383 381 369 359 357 353 347 341 Columns 121 through 130 339 327 323 317 309 299 291 281 273 267 Columns 131 through 140 261 257 249 243 239 231 227 213 203 191 Columns 141 through 150 189 179 177 173 171 161 147 143 141 137 Columns 151 through 160 123 119 117 113 93 89 81 71 63 59 Columns 161 through 168 53 47 33 29 23 17 9 3 i = Columns 1 through 10 2 7 9 10 15 16 17 20 24 30 Columns 11 through 20 33 40 41 43 49 52 55 60 66 69 Columns 21 through 30 71 72 76 79 83 86 92 94 97 98 Columns 31 through 40 102 104 109 113 116 118 119 124 128 132 Columns 41 through 50 135 137 140 142 144 150 154 156 158 160 Columns 51 through 56 161 162 164 165 166 168 p1 = 3 p2 = 997 p1 = 3 p2 = 997 p1 = Columns 1 through 5 2 3 5 7 11 Columns 6 through 10 13 17 19 23 29 Columns 11 through 15 31 37 41 43 47 Columns 16 through 20 53 59 61 67 71 Columns 21 through 25 73 79 83 89 97 Columns 26 through 30 101 103 107 109 113 Columns 31 through 35 127 131 137 139 149 Columns 36 through 40 151 157 163 167 173 Columns 41 through 45 179 181 191 193 197 Columns 46 through 50 199 211 223 227 229 Columns 51 through 55 233 239 241 251 257 Columns 56 through 60 263 269 271 277 281 Columns 61 through 65 283 293 307 311 313 Columns 66 through 70 317 331 337 347 349 Columns 71 through 75 353 359 367 373 379 Columns 76 through 80 383 389 397 401 409 Columns 81 through 85 419 421 431 433 439 Columns 86 through 90 443 449 457 461 463 Columns 91 through 95 467 479 487 491 499 Columns 96 through 100 503 509 521 523 541 Columns 101 through 105 547 557 563 569 571 Columns 106 through 110 577 587 593 599 601 Columns 111 through 115 607 613 617 619 631 Columns 116 through 120 641 643 647 653 659 Columns 121 through 125 661 673 677 683 691 Columns 126 through 130 701 709 719 727 733 Columns 131 through 135 739 743 751 757 761 Columns 136 through 140 769 773 787 797 809 Columns 141 through 145 811 821 823 827 829 Columns 146 through 150 839 853 857 859 863 Columns 151 through 155 877 881 883 887 907 Columns 156 through 160 911 919 929 937 941 Columns 161 through 165 947 953 967 971 977 Columns 166 through 170 983 991 997 1009 1013 Columns 171 through 175 1019 1021 1031 1033 1039 Columns 176 through 180 1049 1051 1061 1063 1069 Columns 181 through 185 1087 1091 1093 1097 1103 Columns 186 through 190 1109 1117 1123 1129 1151 Columns 191 through 195 1153 1163 1171 1181 1187 Columns 196 through 200 1193 1201 1213 1217 1223 Columns 201 through 205 1229 1231 1237 1249 1259 Columns 206 through 210 1277 1279 1283 1289 1291 Columns 211 through 215 1297 1301 1303 1307 1319 Columns 216 through 220 1321 1327 1361 1367 1373 Columns 221 through 225 1381 1399 1409 1423 1427 Columns 226 through 230 1429 1433 1439 1447 1451 Colum...