Cody

# Problem 60. The Goldbach Conjecture

Solution 101051

Submitted on 21 Jun 2012 by MD. MASRUL HUDA
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

prime = 2 3 5 7 11 13 17 19 23 answ = 5 23 answ = 5 23 11 17 answ = 5 23 11 17 17 11 answ = 5 23 11 17 17 11 23 5 b = 5 23 11 17 p1 = 5 p2 = 23 p1 = 5 p2 = 23 prime = Columns 1 through 10 2 3 5 7 11 13 17 19 23 29 Column 11 31 answ = 3 31 answ = 3 31 5 29 answ = 3 31 5 29 11 23 answ = 3 31 5 29 11 23 17 17 answ = 3 31 5 29 11 23 17 17 23 11 answ = 3 31 5 29 11 23 17 17 23 11 29 5 answ = 3 31 5 29 11 23 17 17 23 11 29 5 31 3 {Warning: Integer operands are required for colon operator when used as index} {> In goldbach at 15 In verifyCode>evaluateCode at 189 In verifyCode at 37 In fevalJSON at 14} b = 3 31 5 29 11 23 p1 = 3 p2 = 31 p1 = 3 p2 = 31 prime = Columns 1 through 10 2 3 5 7 11 13 17 19 23 29 Columns 11 through 12 31 37 answ = 3 37 answ = 3 37 11 29 answ = 3 37 11 29 17 23 answ = 3 37 11 29 17 23 23 17 answ = 3 37 11 29 17 23 23 17 29 11 answ = 3 37 11 29 17 23 23 17 29 11 37 3 b = 3 37 11 29 17 23 p1 = 3 p2 = 37 p1 = 3 p2 = 37 prime = Columns 1 through 10 2 3 5 7 11 13 17 19 23 29 Columns 11 through 14 31 37 41 43 answ = 3 43 answ = 3 43 5 41 answ = 3 43 5 41 17 29 answ = 3 43 5 41 17 29 23 23 answ = 3 43 5 41 17 29 23 23 29 17 answ = 3 43 5 41 17 29 23 23 29 17 41 5 answ = 3 43 5 41 17 29 23 23 29 17 41 5 43 3 {Warning: Integer operands are required for colon operator when used as index} {> In goldbach at 15 In verifyCode>evaluateCode at 189 In verifyCode at 37 In fevalJSON at 14} b = 3 43 5 41 17 29 p1 = 3 p2 = 43 p1 = 3 p2 = 43 prime = Columns 1 through 10 2 3 5 7 11 13 17 19 23 29 Columns 11 through 15 31 37 41 43 47 answ = 5 47 answ = 5 47 11 41 answ = 5 47 11 41 23 29 answ = 5 47 11 41 23 29 29 23 answ = 5 47 11 41 23 29 29 23 41 11 answ = 5 47 11 41 23 29 29 23 41 11 47 5 b = 5 47 11 41 23 29 p1 = 5 p2 = 47 p1 = 5 p2 = 47 prime = Columns 1 through 10 2 3 5 7 11 13 17 19 23 29 Columns 11 through 16 31 37 41 43 47 53 answ = 5 53 answ = 5 53 11 47 answ = 5 53 11 47 17 41 answ = 5 53 11 47 17 41 29 29 answ = 5 53 11 47 17 41 29 29 41 17 answ = 5 53 11 47 17 41 29 29 41 17 47 11 answ = 5 53 11 47 17 41 29 29 41 17 47 11 53 5 {Warning: Integer operands are required for colon operator when used as index} {> In goldbach at 15 In verifyCode>evaluateCode at 189 In verifyCode at 37 In fevalJSON at 14} b = 5 53 11 47 17 41 p1 = 5 p2 = 53 p1 = 5 p2 = 53 prime = 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 answ = 3 61 answ = 3 61 5 59 answ = 3 61 5 59 11 53 answ = 3 61 5 59 11 53 17 47 answ = 3 61 5 59 11 53 17 47 23 41 answ = 3 61 5 59 11 53 17 47 23 41 41 23 answ = 3 61 5 59 11 53 17 47 23 41 41 23 47 17 answ = 3 61 5 59 11 53 17 47 23 41 41 23 47 17 53 11 answ = 3 61 5 59 11 53 17 47 23 41 41 23 47 17 53 11 59 5 answ = 3 61 5 59 11 53 17 47 23 41 41 23 47 17 53 11 59 5 61 3 b = 3 61 5 59 11 53 17 47 23 41 p1 = 3 p2 = 61 p1 = 3 p2 = 61 prime = 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 answ = 3 67 answ = 3 67 11 59 answ = 3 67 11 59 17 53 answ = 3 67 11 59 17 53 23 47 answ = 3 67 11 59 17 53 23 47 29 41 answ = 3 67 11 59 17 53 23 47 29 41 41 29 answ = 3 67 11 59 17 53 23 47 29 41 41 29 47 23 answ = 3 67 11 59 17 53 23 47 29 41 41 29 47 23 53 17 answ = 3 67 11 59 17 53 23 47 29 41 41 29 47 23 53 17 59 11 answ = 3 67 11 59 17 53 23 47 29 41 41 29 47 23 53 17 59 11 67 3 b = 3 67 11 59 17 53 23 47 29 41 p1 = 3 p2 = 67 p1 = 3 p2 = 67 prime = 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 answ = 3 73 answ = 3 73 5 71 answ = 3 73 5 71 17 59 answ = 3 73 5 71 17 59 23 53 answ = 3 73 5 71 17 59 23 53 29 47 answ = 3 73 5 71 17 59 23 53 29 47 47 29 answ = 3 73 5 71 17 59 23 53 29 47 47 29 53 23 answ = 3 73 5 71 17 59 23 53 29 47 47 29 53 23 59 17 answ = 3 73 5 71 17 59 23 53 29 47 47 29 53 23 59 17 71 5 answ = 3 73 5 71 17 59 23 53 29 47 47 29 53 23 59 17 71 5 73 3 b = 3 73 5 71 17 59 23 53 29 47 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

prime = 2 3 5 7 11 13 17 answ = 5 13 answ = 5 13 7 11 answ = 5 13 7 11 11 7 answ = 5 13 7 11 11 7 13 5 b = 5 13 7 11 p1 = 5 p2 = 13 p1 = 5 p2 = 13 prime = 2 3 5 7 11 13 17 19 answ = 3 17 answ = 3 17 7 13 answ = 3 17 7 13 13 7 answ = 3 17 7 13 13 7 17 3 b = 3 17 7 13 p1 = 3 p2 = 17 p1 = 3 p2 = 17 prime = 2 3 5 7 11 13 17 19 answ = 3 19 answ = 3 19 5 17 answ = 3 19 5 17 11 11 answ = 3 19 5 17 11 11 17 5 answ = 3 19 5 17 11 11 17 5 19 3 {Warning: Integer operands are required for colon operator when used as index} {> In goldbach at 15 In verifyCode>evaluateCode at 189 In verifyCode at 37 In fevalJSON at 14} b = 3 19 5 17 p1 = 3 p2 = 19 p1 = 3 p2 = 19 prime = 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 answ = 3 97 answ = 3 97 11 89 answ = 3 97 11 89 17 83 answ = 3 97 11 89 17 83 29 71 answ = 3 97 11 89 17 83 29 71 41 59 answ = 3 97 11 89 17 83 29 71 41 59 47 53 answ = 3 97 11 89 17 83 29 71 41 59 47 53 53 47 answ = 3 97 11 89 17 83 29 71 41 59 47 53 53 47 59 41 answ = 3 97 11 89 17 83 29 71 41 59 47 53 53 47 59 41 71 29 answ = 3 97 11 89 17 83 29 71 41 59 47 53 53 47 59 41 71 29 83 17 answ = 3 97 11 89 17 83 29 71 41 59 47 53 53 47 59 41 71 29 83 17 89 11 answ = 3 97 11 89 17 83 29 71 41 59 47 53 53 47 59 41 71 29 83 17 89 11 97 3 b = 3 97 11 89 17 83 29 71 41 59 47 53 p1 = 3 p2 = 97 p1 = 3 p2 = 97 prime = 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 answ = 5 97 answ = 5 97 13 89 answ = 5 97 13 89 19 83 answ = 5 97 13 89 19 83 23 79 answ = 5 97 13 89 19 83 23 79 29 73 answ = 5 97 13 89 19 83 23 79 29 73 31 71 answ = 5 97 13 89 19 83 23 79 29 73 31 71 41 61 answ = 5 97 13 89 19 83 23 79 29 73 31 71 41 61 43 59 answ = 5 97 13 89 19 83 23 79 29 73 31 71 41 61 43 59 59 43 answ = 5 97 13 89 19 83 23 79 29 73 31 71 41 61 43 59 59 43 61 41 answ = 5 97 13 89 19 83 23 79 29 73 31 71 41 61 43 59 59 43 61 41 71 31 answ = 5 97 13 89 19 83 23 79 29 73 31 71 41 61 43 59 59 43 61 41 71 31 73 29 answ = 5 97 13 89 19 83 23 79 29 73 31 71 41 61 43 59 59 43 61 41 71 31 73 29 79 23 answ = 5 97 13 89 19 83 23 79 29 73 31 71 41 61 43 59 59 43 61 41 71 31 73 29 79 23 83 19 answ = 5 97 13 89 19 83 23 79 29 73 31 71 41 61 43 59 59 43 61 41 71 31 73 29 79 23 83 19 89 13 answ = 5 97 13 89 19 83 23 79 29 73 31 71 41 61 43 59 59 43 61 41 71 31 73 29 79 23 83 19 89 13 97 5 b = 5 97 13 89 19 83 23 79 29 73 31 71 41 61 43 59 p1 = 5 p2 = 97 p1 = 5 p2 = 97 prime = 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 answ = 5 109 answ = 5 109 7 107 answ = 5 109 7 107 11 103 answ = 5 109 7 107 11 103 13 101 answ = 5 109 7 107 11 103 13 101 17 97 answ = 5 109 7 107 11 103 13 101 17 97 31 83 answ = 5 109 7 107 11 103 13 101 17 97 31 83 41 73 answ = 5 109 7 107 11 103 13 101 17 97 31 83 41 73 43 71 answ = 5 109 7 107 11 103 13 101 17 97 31 83 41 73 43 71 47 67 answ = 5 109 7 107 11 103 13 101 17 97 31 83 41 73 43 71 47 67 53 61 answ = 5 109 7 107 11 103 13 101 17 97 31 83 41 73 43 71 47 67 53 61 61 53 answ = 5 109 7 107 11 103 13 101 17 97 31 83 41 73 43 71 47 67 53 61 61 53 67 47 answ = 5 109 7 107 11 103 13 101 17 97 31 83 41 73 43 71 47 67 53 61 61 53 67 47 71 43 answ = 5 109 7 107 11 103 13 101 17 97 31 83 41 73 43 71 47 67 53 61 61 53 67 47 71 43 73 41 answ = 5 109 7 107 11 103 13 101 17 97 31 83 41 73 43 71 47 67 53 61 61 53 67 47 71 43 73 41 83 31 answ = 5 109 7 107 11 103 13 101 17 97 31 83 41 73 43 71 47 67 53 61 61 53 67 47 71 43 73 41 83 31 97 17 answ = 5 109 7 107 11 103 13 101 17 97 31 83 41 73 43 71 47 67 53 61 61 53 67 47 71 43 73 41 83 31 97 17 101 13 answ = 5 109 7 107 11 103 13 101 17 97 31 83 41 73 43 71 47 67 53 61 61 53 67 47 71 43 73 41 83 31 97 17 101 13 103 11 answ = 5 109 7 107 11 103 13 101 17 97 31 83 41 73 43 71 47 67 53 61 61 53 67 47 71 43 73 41 83 31 97 17 101 13 103 11 107 7 answ = 5 109 7 107 11 103 13 101 17 97 31 83 41 73 43 71 47 67 53 61 61 53 67 47 71 43 73 41 83 31 97 17 101 13 103 11 107 7 109 5 b = 5 109 7 107 11 103 13 101 17 97 31 83 41 73 43 71 47 67 53 61 p1 = 5 p2 = 109 p1 = 5 p2 = 109 prime = 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 answ = 3 997 answ = 3 997 17 983 answ = 3 997 17 983 23 977 answ = 3 997 17 983 23 977 29 971 answ = 3 997 17 983 23 977 29 971 47 953 answ = 3 997 17 983 23 977 29 971 47 953 53 947 answ = 3 997 17 983 23 977 29 9...