Cody

# Problem 44360. Pentagonal Numbers

Solution 1330045

Submitted on 6 Nov 2017 by Lane Maxwell
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
x1 = 1; x2 = 25; [p,d] = pentagonal_numbers(x1,x2) assert(isequal(p,[1,5,12,22])) assert(isequal(d,[0,1,0,0]))

p = 1 d = 0 p = 1 5 d = 0 1 p = 1 5 12 d = 0 1 0 p = 1 5 12 22 d = 0 1 0 0 p = 1 5 12 22 d = 0 1 0 0

2   Pass
x1 = 1; x2 = 4; [p,d] = pentagonal_numbers(x1,x2) assert(isequal(p,1)) assert(isequal(d,0))

p = 1 d = 0 p = 1 d = 0

3   Pass
x1 = 10; x2 = 40; [p,d] = pentagonal_numbers(x1,x2) assert(isequal(p,[12,22,35])) assert(isequal(d,[0,0,1]))

p = 12 d = 0 p = 12 22 d = 0 0 p = 12 22 35 d = 0 0 1 p = 12 22 35 d = 0 0 1

4   Pass
x1 = 10; x2 = 99; [p,d] = pentagonal_numbers(x1,x2) assert(isequal(p,[12,22,35,51,70,92])) assert(isequal(d,[0,0,1,0,1,0]))

p = 12 d = 0 p = 12 22 d = 0 0 p = 12 22 35 d = 0 0 1 p = 12 22 35 51 d = 0 0 1 0 p = 12 22 35 51 70 d = 0 0 1 0 1 p = 12 22 35 51 70 92 d = 0 0 1 0 1 0 p = 12 22 35 51 70 92 d = 0 0 1 0 1 0

5   Pass
x1 = 100; x2 = 999; [p,d] = pentagonal_numbers(x1,x2) assert(isequal(p,[117,145,176,210,247,287,330,376,425,477,532,590,651,715,782,852,925])) assert(isequal(d,[0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1]))

p = 117 d = 0 p = 117 145 d = 0 1 p = 117 145 176 d = 0 1 0 p = 117 145 176 210 d = 0 1 0 1 p = 117 145 176 210 247 d = 0 1 0 1 0 p = 117 145 176 210 247 287 d = 0 1 0 1 0 0 p = 117 145 176 210 247 287 330 d = 0 1 0 1 0 0 1 p = 117 145 176 210 247 287 330 376 d = 0 1 0 1 0 0 1 0 p = 117 145 176 210 247 287 330 376 425 d = 0 1 0 1 0 0 1 0 1 p = 117 145 176 210 247 287 330 376 425 477 d = 0 1 0 1 0 0 1 0 1 0 p = 117 145 176 210 247 287 330 376 425 477 532 d = 0 1 0 1 0 0 1 0 1 0 0 p = 117 145 176 210 247 287 330 376 425 477 532 590 d = 0 1 0 1 0 0 1 0 1 0 0 1 p = 117 145 176 210 247 287 330 376 425 477 532 590 651 d = 0 1 0 1 0 0 1 0 1 0 0 1 0 p = 117 145 176 210 247 287 330 376 425 477 532 590 651 715 d = 0 1 0 1 0 0 1 0 1 0 0 1 0 1 p = 117 145 176 210 247 287 330 376 425 477 532 590 651 715 782 d = 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 p = 117 145 176 210 247 287 330 376 425 477 532 590 651 715 782 852 d = 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 p = 117 145 176 210 247 287 330 376 425 477 532 590 651 715 782 852 925 d = 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 p = 117 145 176 210 247 287 330 376 425 477 532 590 651 715 782 852 925 d = 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1

6   Pass
x1 = 40; x2 = 50; [p,d] = pentagonal_numbers(x1,x2) assert(isempty(p)) assert(isempty(d))

p = [] d = []

7   Pass
x1 = 1000; x2 = 1500; [p,d] = pentagonal_numbers(x1,x2) assert(isequal(p,[1001,1080,1162,1247,1335,1426])) assert(isequal(d,[0,1,0,0,1,0]))

p = 1001 d = 0 p = 1001 1080 d = 0 1 p = 1001 1080 1162 d = 0 1 0 p = 1001 1080 1162 1247 d = 0 1 0 0 p = 1001 1080 1162 1247 1335 d = 0 1 0 0 1 p = 1001 1080 1162 1247 1335 1426 d = 0 1 0 0 1 0 p = 1001 1080 1162 1247 1335 1426 d = 0 1 0 0 1 0

8   Pass
x1 = 1500; x2 = 3000; [p,d] = pentagonal_numbers(x1,x2) assert(isequal(p,[1520,1617,1717,1820,1926,2035,2147,2262,2380,2501,2625,2752,2882])) assert(isequal(d,[1,0,0,1,0,1,0,0,1,0,1,0,0]))

p = 1520 d = 1 p = 1520 1617 d = 1 0 p = 1520 1617 1717 d = 1 0 0 p = 1520 1617 1717 1820 d = 1 0 0 1 p = 1520 1617 1717 1820 1926 d = 1 0 0 1 0 p = 1520 1617 1717 1820 1926 2035 d = 1 0 0 1 0 1 p = 1520 1617 1717 1820 1926 2035 2147 d = 1 0 0 1 0 1 0 p = 1520 1617 1717 1820 1926 2035 2147 2262 d = 1 0 0 1 0 1 0 0 p = 1520 1617 1717 1820 1926 2035 2147 2262 2380 d = 1 0 0 1 0 1 0 0 1 p = 1520 1617 1717 1820 1926 2035 2147 2262 2380 2501 d = 1 0 0 1 0 1 0 0 1 0 p = 1520 1617 1717 1820 1926 2035 2147 2262 2380 2501 2625 d = 1 0 0 1 0 1 0 0 1 0 1 p = 1520 1617 1717 1820 1926 2035 2147 2262 2380 2501 2625 2752 d = 1 0 0 1 0 1 0 0 1 0 1 0 p = 1520 1617 1717 1820 1926 2035 2147 2262 2380 2501 2625 2752 2882 d = 1 0 0 1 0 1 0 0 1 0 1 0 0 p = 1520 1617 1717 1820 1926 2035 2147 2262 2380 2501 2625 2752 2882 d = 1 0 0 1 0 1 0 0 1 0 1 0 0

9   Pass
x1 = 1; x2 = 3000; [p,d] = pentagonal_numbers(x1,x2) assert(isequal(p,[1,5,12,22,35,51,70,92,117,145,176,210,247,287,330,376,425,477,532,590,651,715,782,852,925,1001,1080,1162,1247,1335,1426,1520,1617,1717,1820,1926,2035,2147,2262,2380,2501,2625,2752,2882])) assert(isequal(d,[0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0]))

p = 1 d = 0 p = 1 5 d = 0 1 p = 1 5 12 d = 0 1 0 p = 1 5 12 22 d = 0 1 0 0 p = 1 5 12 22 35 d = 0 1 0 0 1 p = 1 5 12 22 35 51 d = 0 1 0 0 1 0 p = 1 5 12 22 35 51 70 d = 0 1 0 0 1 0 1 p = 1 5 12 22 35 51 70 92 d = 0 1 0 0 1 0 1 0 p = 1 5 12 22 35 51 70 92 117 d = 0 1 0 0 1 0 1 0 0 p = 1 5 12 22 35 51 70 92 117 145 d = 0 1 0 0 1 0 1 0 0 1 p = 1 5 12 22 35 51 70 92 117 145 176 d = 0 1 0 0 1 0 1 0 0 1 0 p = 1 5 12 22 35 51 70 92 117 145 176 210 d = 0 1 0 0 1 0 1 0 0 1 0 1 p = 1 5 12 22 35 51 70 92 117 145 176 210 247 d = 0 1 0 0 1 0 1 0 0 1 0 1 0 p = 1 5 12 22 35 51 70 92 117 145 176 210 247 287 d = 0 1 0 0 1 0 1 0 0 1 0 1 0 0 p = 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 d = 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 p = 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 376 d = 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 p = 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 376 425 d = 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 p = 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 376 425 477 d = 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 p = 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 376 425 477 532 d = 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 p = 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 376 425 477 532 590 d = 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 p = 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 376 425 477 532 590 651 d = 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 p = 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 376 425 477 532 590 651 715 d = 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 p = 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 376 425 477 532 590 651 715 782 d = 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 p = 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 376 425 477 532 590 651 715 782 852 d = 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 p = 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 376 425 477 532 590 651 715 782 852 925 d = 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 p = Columns 1 through 15 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 Columns 16 through 26 376 425 477 532 590 651 715 782 852 925 1001 d = 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 p = Columns 1 through 15 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 Columns 16 through 27 376 425 477 532 590 651 715 782 852 925 1001 1080 d = 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 p = Columns 1 through 15 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 Columns 16 through 28 376 425 477 532 590 651 715 782 852 925 1001 1080 1162 d = 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 p = Columns 1 through 15 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 Columns 16 through 29 376 425 477 532 590 651 715 782 852 925 1001 1080 1162 1247 d = 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 p = Columns 1 through 15 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 Columns 16 through 30 376 425 477 532 590 651 715 782 852 925 1001 1080 1162 1247 1335 d = 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 p = Columns 1 through 15 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 Columns 16 through 30 376 425 477 532 590 651 715 782 852 925 1001 1080 1162 1247 1335 Column 31 1426 d = Columns 1 through 30 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 Column 31 0 p = Columns 1 through 15 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 Columns 16 through 30 376 425 477 532 590 651 715 782 852 925 1001 1080 1162 1247 1335 Columns 31 through 32 1426 1520 d = Columns 1 through 30 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 Columns 31 through 32 0 1 p = Columns 1 through 15 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 Columns 16 through 30 376 425 477 532 590 651 715 782 852 925 1001 1080 1162 1247 1335 Columns 31 through 33 1426 1520 1617 d = Columns 1 through 30 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 Columns 31 through 33 0 1 0 p = Columns 1 through 15 1 5 12 22 35 51 70 92 117 145 176 210 247 287 330 Columns 16 through 30 376 425 477 532 590 651 715 782 852 925 1001 1080 1162 1247 1335 Columns 31 through 34 1426 1520 1617 1717 d = Columns 1 through 30 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 ...

10   Pass
x1 = 10000; x2 = 12000; [p,d] = pentagonal_numbers(x1,x2) assert(isequal(p,[10045,10292,10542,10795,11051,11310,11572,11837])) assert(isequal(d,[1,0,0,1,0,1,0,0]))

p = 10045 d = 1 p = 10045 10292 d = 1 0 p = 10045 10292 10542 d = 1 0 0 p = 10045 10292 10542 10795 d = 1 0 0 1 p = 10045 10292 10542 10795 11051 d = 1 0 0 1 0 p = 10045 10292 10542 10795 11051 11310 d = 1 0 0 1 0 1 p = 10045 10292 10542 10795 11051 11310 11572 d = 1 0 0 1 0 1 0 p = 10045 10292 10542 10795 11051 11310 11572 11837 d = 1 0 0 1 0 1 0 0 p = 10045 10292 10542 10795 11051 11310 11572 11837 d = 1 0 0 1 0 1 0 0

11   Pass
x1 = 100000; x2 = 110000; [p,d] = pentagonal_numbers(x1,x2) assert(isequal(p,[100492,101270,102051,102835,103622,104412,105205,106001,106800,107602,108407,109215])) assert(isequal(d,[0,1,0,1,0,0,1,0,1,0,0,1]))

p = 100492 d = 0 p = 100492 101270 d = 0 1 p = 100492 101270 102051 d = 0 1 0 p = 100492 101270 102051 102835 d = 0 1 0 1 p = 100492 101270 102051 102835 103622 d = 0 1 0 1 0 p = 100492 101270 102051 102835 103622 104412 d = 0 1 0 1 0 0 p = 100492 101270 102051 102835 103622 104412 105205 d = 0 1 0 1 0 0 1 p = 100492 101270 102051 102835 103622 104412 105205 106001 d = 0 1 0 1 0 0 1 0 p = 100492 101270 102051 102835 103622 104412 105205 106001 106800 d = 0 1 0 1 0 0 1 0 1 p = 100492 101270 102051 102835 103622 104412 105205 106001 106800 107602 d = 0 1 0 1 0 0 1 0 1 0 p = 100492 101270 102051 102835 103622 104412 105205 106001 106800 107602 108407 d = 0 1 0 1 0 0 1 0 1 0 0 p = 100492 101270 102051 102835 103622 104412 105205 106001 106800 107602 108407 109215 d = 0 1 0 1 0 0 1 0 1 0 0 1 p = 100492 101270 102051 102835 103622 104412 105205 106001 106800 107602 108407 109215 d = 0 1 0 1 0 0 1 0 1 0 0 1

12   Pass
x1 = 1000000; x2 = 1010101; [p,d] = pentagonal_numbers(x1,x2) assert(isequal(p,[1000825,1003277,1005732,1008190])) assert(isequal(d,[1,0,0,1]))

p = 1000825 d = 1 p = 1000825 1003277 d = 1 0 p = 1000825 1003277 1005732 d = 1 0 0 p = 1000825 1003277 1005732 1008190 d = 1 0 0 1 p = 1000825 1003277 1005732 1008190 d = 1 0 0 1

### Community Treasure Hunt

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

Start Hunting!