Cody

# Problem 60. The Goldbach Conjecture

Solution 1383950

Submitted on 18 Dec 2017 by Richard
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 = 5 ans = 23 p1 = 11 ans = 17 p1 = 17 ans = 11 p1 = 23 ans = 5 p1 = 23 p2 = 5 p1 = 3 ans = 31 p1 = 5 ans = 29 p1 = 11 ans = 23 p1 = 17 ans = 17 p1 = 23 ans = 11 p1 = 29 ans = 5 p1 = 31 ans = 3 p1 = 31 p2 = 3 p1 = 3 ans = 37 p1 = 11 ans = 29 p1 = 17 ans = 23 p1 = 23 ans = 17 p1 = 29 ans = 11 p1 = 37 ans = 3 p1 = 37 p2 = 3 p1 = 3 ans = 43 p1 = 5 ans = 41 p1 = 17 ans = 29 p1 = 23 ans = 23 p1 = 29 ans = 17 p1 = 41 ans = 5 p1 = 43 ans = 3 p1 = 43 p2 = 3 p1 = 5 ans = 47 p1 = 11 ans = 41 p1 = 23 ans = 29 p1 = 29 ans = 23 p1 = 41 ans = 11 p1 = 47 ans = 5 p1 = 47 p2 = 5 p1 = 5 ans = 53 p1 = 11 ans = 47 p1 = 17 ans = 41 p1 = 29 ans = 29 p1 = 41 ans = 17 p1 = 47 ans = 11 p1 = 53 ans = 5 p1 = 53 p2 = 5 p1 = 3 ans = 61 p1 = 5 ans = 59 p1 = 11 ans = 53 p1 = 17 ans = 47 p1 = 23 ans = 41 p1 = 41 ans = 23 p1 = 47 ans = 17 p1 = 53 ans = 11 p1 = 59 ans = 5 p1 = 61 ans = 3 p1 = 61 p2 = 3 p1 = 3 ans = 67 p1 = 11 ans = 59 p1 = 17 ans = 53 p1 = 23 ans = 47 p1 = 29 ans = 41 p1 = 41 ans = 29 p1 = 47 ans = 23 p1 = 53 ans = 17 p1 = 59 ans = 11 p1 = 67 ans = 3 p1 = 67 p2 = 3 p1 = 3 ans = 73 p1 = 5 ans = 71 p1 = 17 ans = 59 p1 = 23 ans = 53 p1 = 29 ans = 47 p1 = 47 ans = 29 p1 = 53 ans = 23 p1 = 59 ans = 17 p1 = 71 ans = 5 p1 = 73 ans = 3 p1 = 73 p2 = 3

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 = 5 ans = 13 p1 = 7 ans = 11 p1 = 11 ans = 7 p1 = 13 ans = 5 p1 = 13 p2 = 5 p1 = 3 ans = 17 p1 = 7 ans = 13 p1 = 13 ans = 7 p1 = 17 ans = 3 p1 = 17 p2 = 3 p1 = 3 ans = 19 p1 = 5 ans = 17 p1 = 11 ans = 11 p1 = 17 ans = 5 p1 = 19 ans = 3 p1 = 19 p2 = 3 p1 = 3 ans = 97 p1 = 11 ans = 89 p1 = 17 ans = 83 p1 = 29 ans = 71 p1 = 41 ans = 59 p1 = 47 ans = 53 p1 = 53 ans = 47 p1 = 59 ans = 41 p1 = 71 ans = 29 p1 = 83 ans = 17 p1 = 89 ans = 11 p1 = 97 ans = 3 p1 = 97 p2 = 3 p1 = 5 ans = 97 p1 = 13 ans = 89 p1 = 19 ans = 83 p1 = 23 ans = 79 p1 = 29 ans = 73 p1 = 31 ans = 71 p1 = 41 ans = 61 p1 = 43 ans = 59 p1 = 59 ans = 43 p1 = 61 ans = 41 p1 = 71 ans = 31 p1 = 73 ans = 29 p1 = 79 ans = 23 p1 = 83 ans = 19 p1 = 89 ans = 13 p1 = 97 ans = 5 p1 = 97 p2 = 5 p1 = 5 ans = 109 p1 = 7 ans = 107 p1 = 11 ans = 103 p1 = 13 ans = 101 p1 = 17 ans = 97 p1 = 31 ans = 83 p1 = 41 ans = 73 p1 = 43 ans = 71 p1 = 47 ans = 67 p1 = 53 ans = 61 p1 = 61 ans = 53 p1 = 67 ans = 47 p1 = 71 ans = 43 p1 = 73 ans = 41 p1 = 83 ans = 31 p1 = 97 ans = 17 p1 = 101 ans = 13 p1 = 103 ans = 11 p1 = 107 ans = 7 p1 = 109 ans = 5 p1 = 109 p2 = 5 p1 = 3 ans = 997 p1 = 17 ans = 983 p1 = 23 ans = 977 p1 = 29 ans = 971 p1 = 47 ans = 953 p1 = 53 ans = 947 p1 = 59 ans = 941 p1 = 71 ans = 929 p1 = 89 ans = 911 p1 = 113 ans = 887 p1 = 137 ans = 863 p1 = 173 ans = 827 p1 = 179 ans = 821 p1 = 191 ans = 809 p1 = 227 ans = 773 p1 = 239 ans = 761 p1 = 257 ans = 743 p1 = 281 ans = 719 p1 = 317 ans = 683 p1 = 347 ans = 653 p1 = 353 ans = 647 p1 = 359 ans = 641 p1 = 383 ans = 617 p1 = 401 ans = 599 p1 = 431 ans = 569 p1 = 443 ans = 557 p1 = 479 ans = 521 p1 = 491 ans = 509 p1 = 509 ans = 491 p1 = 521 ans = 479 p1 = 557 ans = 443 p1 = 569 ans = 431 p1 = 599 ans = 401 p1 = 617 ans = 383 p1 = 641 ans = 359 p1 = 647 ans = 353 p1 = 653 ans = 347 p1 = 683 ans = 317 p1 = 719 ans = 281 p1 = 743 ans = 257 p1 = 761 ans = 239 p1 = 773 ans = 227 p1 = 809 ans = 191 p1 = 821 ans = 179 p1 = 827 ans = 173 p1 = 863 ans = 137 p1 = 887 ans = 113 p1 = 911 ans = 89 p1 = 929 ans = 71 p1 = 941 ans = 59 p1 = 947 ans = 53 p1 = 953 ans = 47 p1 = 971 ans = 29 p1 = 977 ans = 23 p1 = 983 ans = 17 p1 = 997 ans = 3 p1 = 997 p2 = 3 p1 = 3 ans = 1997 p1 = 7 ans = 1993 p1 = 13 ans = 1987 p1 = 67 ans = 1933 p1 = 127 ans = 1873 p1 = 139 ans = 1861 p1 = 199 ans = 1801 p1 = 211 ans = 1789 p1 = 223 ans = 1777 p1 = 241 ans = 1759 p1 = 277 ans = 1723 p1 = 307 ans = 1693 p1 = 331 ans = 1669 p1 = 337 ans = 1663 p1 = 373 ans = 1627 p1 = 379 ans = 1621 p1 = 421 ans = 1579 p1 = 433 ans = 1567 p1 = 457 ans = 1543 p1 = 541 ans = 1459 p1 = 547 ans = 1453 p1 = 571 ans = 1429 p1 = 577 ans = 1423 p1 = 601 ans = 1399 p1 = 619 ans = 1381 p1 = 673 ans = 1327 p1 = 709 ans = 1291 p1 = 751 ans = 1249 p1 = 769 ans = 1231 p1 = 787 ans = 1213 p1 = 829 ans = 1171 p1 = 877 ans = 1123 p1 = 883 ans = 1117 p1 = 907 ans = 1093 p1 = 937 ans = 1063 p1 = 967 ans = 1033 p1 = 991 ans = 1009 p1 = 1009 ans = 991 p1 = 1033 ans = 967 p1 = 1063 ans = 937 p1 = 1093 ans = 907 p1 = 1117 ans = 883 p1 = 1123 ans = 877 p1 = 1171 ans = 829 p1 = 1213 ans = 787 p1 = 1231 ans = 769 p1 = 1249 ans = 751 p1 = 1291 ans = 709 p1 = 1327 ans = 673 p1 = 1381 ans = 619 p1 = 1399 ans = 601 p1 = 1423 ans = 577 p1 = 1429 ans = 571 p1 = 1453 ans = 547 p1 = 1459 ans = 541 p1 = 1543 ans = 457 p1 = 1567 ans = 433 p1 = 1579 ans = 421 p1 = 1621 ans = 379 p1 = 1627 ans = 373 p1 = 1663 ans = 337 p1 = 1669 ans = 331 p1 = 1693 ans = 307 p1 = 1723 ans = 277 p1 = 1759 ans = 241 p1 = 1777 ans = 223 p1 = 1789 ans = 211 p1 = 1801 ans = 199 p1 = 1861 ans = 139 p1 = 1873 ans = 127 p1 = 1933 ans = 67 p1 = 1987 ans = 13 p1 = 1993 ans = 7 p1 = 1997 ans = 3 p1 = 1997 p2 = 3 p1 = 5 ans = 31 p1 = 7 ans = 29 p1 = 13 ans = 23 p1 = 17 ans = 19 p1 = 19 ans = 17 p1 = 23 ans = 13 p1 = 29 ans = 7 p1 = 31 ans = 5 p1 = 31 p2 = 5 p1 = 7 ans = 3593 p1 = 17 ans = 3583 p1 = 19 ans = 3581 p1 = 29 ans = 3571 p1 = 41 ans = 3559 p1 = 43 ans = 3557 p1 = 53 ans = 3547 p1 = 59 ans = 3541 p1 = 61 ans = 3539 p1 = 67 ans = 3533 p1 = 71 ans = 3529 p1 = 73 ans = 3527 p1 = 83 ans = 3517 p1 = 89 ans = 3511 p1 = 101 ans = 3499 p1 = 109 ans = 3491 p1 = 131 ans = 3469 p1 = 137 ans = 3463 p1 = 139 ans = 3461 p1 = 151 ans = 3449 p1 = 167 ans = 3433 p1 = 193 ans = 3407 p1 = 211 ans = 3389 p1 = 227 ans = 3373 p1 = 229 ans = 3371 p1 = 239 ans = 3361 p1 = 241 ans = 3359 p1 = 257 ans = 3343 p1 = 269 ans = 3331 p1 = 271 ans = 3329 p1 = 277 ans = 3323 p1 = 281 ans = 3319 p1 = 293 ans = 3307 p1 = 347 ans = 3253 p1 = 349 ans = 3251 p1 = 379 ans = 3221 p1 = 383 ans = 3217 p1 = 397 ans = 3203 p1 = 409 ans = 3191 p1 = 419 ans = 3181 p1 = 431 ans = 3169 p1 = 433 ans = 3167 p1 = 463 ans = 3137 p1 = 479 ans = 3121 p1 = 491 ans = 3109 p1 = 521 ans = 3079 p1 = 563 ans = 3037 p1 = 577 ans = 3023 p1 = 599 ans = 3001 p1 = 601 ans = 2999 p1 = 631 ans = 2969 p1 = 643 ans = 2957 p1 = 647 ans = 2953 p1 = 661 ans = 2939 p1 = 673 ans = 2927 p1 = 683 ans = 2917 p1 = 691 ans = 2909 p1 = 739 ans = 2861 p1 = 743 ans = 2857 p1 = 757 ans = 2843 p1 = 797 ans = 2803 p1 = 809 ans = 2791 p1 = 811 ans = 2789 p1 = 823 ans = 2777 p1 = 859 ans = 2741 p1 = 881 ans = 2719 p1 = 887 ans = 2713 p1 = 907 ans = 2693 p1 = 911 ans = 2689 p1 = 929 ans = 2671 p1 = 937 ans = 2663 p1 = 941 ans = 2659 p1 = 953 ans = 2647 p1 = 967 ans = 2633 p1 = 983 ans = 2617 p1 = 991 ans = 2609 p1 = 1009 ans = 2591 p1 = 1021 ans = 2579 p1 = 1049 ans = 2551 p1 = 1051 ans = 2549 p1 = 1061 ans = 2539 p1 = 1069 ans = 2531 p1 = 1097 ans = 2503 ...