Cody

# Problem 1298. P-smooth numbers

Solution 1921363

Submitted on 4 Sep 2019 by Virtual AS
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
vs = find_psmooth(2,16); assert(isequal(vs,[1 2 4 8 16]))

vs = 1 2 4 8 16

2   Pass
vs = find_psmooth(3,128); assert(isequal(vs,[1, 2, 3, 4, 6, 8, 9, 12, 16, 18, 24, 27, 32, 36, 48, 54, 64, 72, 81, 96, 108, 128]))

vs = 1 2 3 4 6 8 9 12 16 18 24 27 32 36 48 54 64 72 81 96 108 128

3   Pass
vs = find_psmooth(11,73); assert(isequal(vs,[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 27, 28, 30, 32, 33, 35, 36, 40, 42, 44, 45, 48, 49, 50, 54, 55, 56, 60, 63, 64, 66, 70, 72]))

vs = Columns 1 through 30 1 2 3 4 5 6 7 8 9 10 11 12 14 15 16 18 20 21 22 24 25 27 28 30 32 33 35 36 40 42 Columns 31 through 44 44 45 48 49 50 54 55 56 60 63 64 66 70 72

4   Pass
pmax=7; vmax=120; vs = find_psmooth(pmax,vmax); vs=unique(vs); % Validity checks vs(vs>vmax)=[]; vs(vs<1)=[]; vs=floor(vs); length(vs) if length(vs)==50 % Known length pass=true; else pass=false; end pv=primes(vmax); pv(pv<=pmax)=[]; for i=pv if any(mod(vs,i)==0) % check for prime divisors >pmax pass=false; break; end end assert(pass)

vs = Columns 1 through 30 1 2 3 4 5 6 7 8 9 10 12 14 15 16 18 20 21 24 25 27 28 30 32 35 36 40 42 45 48 49 Columns 31 through 50 50 54 56 60 63 64 70 72 75 80 81 84 90 96 98 100 105 108 112 120 ans = 50

5   Pass
pmax=11; vmax=300; vs = find_psmooth(pmax,vmax); vs=unique(vs); % Validity checks vs(vs>vmax)=[]; vs(vs<1)=[]; vs=floor(vs); length(vs) if length(vs)==104 % Known length pass=true; else pass=false; end pv=primes(vmax); pv(pv<=pmax)=[]; for i=pv if any(mod(vs,i)==0) % check for prime divisors >pmax pass=false; break; end end assert(pass)

vs = Columns 1 through 30 1 2 3 4 5 6 7 8 9 10 11 12 14 15 16 18 20 21 22 24 25 27 28 30 32 33 35 36 40 42 Columns 31 through 60 44 45 48 49 50 54 55 56 60 63 64 66 70 72 75 77 80 81 84 88 90 96 98 99 100 105 108 110 112 120 Columns 61 through 90 121 125 126 128 132 135 140 144 147 150 154 160 162 165 168 175 176 180 189 192 196 198 200 210 216 220 224 225 231 240 Columns 91 through 104 242 243 245 250 252 256 264 270 275 280 288 294 297 300 ans = 104

6   Pass
pmax=13; vmax=900; vs = find_psmooth(pmax,vmax); vs=unique(vs); % Validity checks vs(vs>vmax)=[]; vs(vs<1)=[]; vs=floor(vs); length(vs) if length(vs)==231% Known length pass=true; else pass=false; end pv=primes(vmax); pv(pv<=pmax)=[]; for i=pv if any(mod(vs,i)==0) % check for prime divisors >pmax pass=false; break; end end assert(pass)

vs = Columns 1 through 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 18 20 21 22 24 25 26 27 28 30 32 33 35 36 Columns 31 through 60 39 40 42 44 45 48 49 50 52 54 55 56 60 63 64 65 66 70 72 75 77 78 80 81 84 88 90 91 96 98 Columns 61 through 90 99 100 104 105 108 110 112 117 120 121 125 126 128 130 132 135 140 143 144 147 150 154 156 160 162 165 168 169 175 176 Columns 91 through 120 180 182 189 192 195 196 198 200 208 210 216 220 224 225 231 234 240 242 243 245 250 252 256 260 264 270 273 275 280 286 Columns 121 through 150 288 294 297 300 308 312 315 320 324 325 330 336 338 343 350 351 352 360 363 364 375 378 384 385 390 392 396 400 405 416 Columns 151 through 180 420 429 432 440 441 448 450 455 462 468 480 484 486 490 495 500 504 507 512 520 525 528 539 540 546 550 560 567 572 576 Columns 181 through 210 585 588 594 600 605 616 624 625 630 637 640 648 650 660 672 675 676 686 693 700 702 704 715 720 726 728 729 735 750 756 Columns 211 through 231 768 770 780 784 792 800 810 819 825 832 840 845 847 858 864 875 880 882 891 896 900 ans = 231

### Community Treasure Hunt

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

Start Hunting!