Cody

Problem 46600. Generate a list of composite numbers

Solution 3032935

Submitted on 2 Oct 2020 by James
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
n = 10; c_correct = [4 6 8 9 10]; assert(isequal(composites(n),c_correct))

ans = 4 6 8 9 10

2   Pass
n = 31; c_correct = [4 6 8 9 10 12 14 15 16 18 20 21 22 24 25 26 27 28 30]; assert(isequal(composites(n),c_correct))

ans = 4 6 8 9 10 12 14 15 16 18 20 21 22 24 25 26 27 28 30

3   Pass
n = 500; c = composites(n); len_correct = 404; c_correct80 = [110 207 303 399 495]; assert(isequal(length(c),len_correct) && isequal(c(80:80:end),c_correct80))

ans = Columns 1 through 29 4 6 8 9 10 12 14 15 16 18 20 21 22 24 25 26 27 28 30 32 33 34 35 36 38 39 40 42 44 Columns 30 through 58 45 46 48 49 50 51 52 54 55 56 57 58 60 62 63 64 65 66 68 69 70 72 74 75 76 77 78 80 81 Columns 59 through 87 82 84 85 86 87 88 90 91 92 93 94 95 96 98 99 100 102 104 105 106 108 110 111 112 114 115 116 117 118 Columns 88 through 116 119 120 121 122 123 124 125 126 128 129 130 132 133 134 135 136 138 140 141 142 143 144 145 146 147 148 150 152 153 Columns 117 through 145 154 155 156 158 159 160 161 162 164 165 166 168 169 170 171 172 174 175 176 177 178 180 182 183 184 185 186 187 188 Columns 146 through 174 189 190 192 194 195 196 198 200 201 202 203 204 205 206 207 208 209 210 212 213 214 215 216 217 218 219 220 221 222 Columns 175 through 203 224 225 226 228 230 231 232 234 235 236 237 238 240 242 243 244 245 246 247 248 249 250 252 253 254 255 256 258 259 Columns 204 through 232 260 261 262 264 265 266 267 268 270 272 273 274 275 276 278 279 280 282 284 285 286 287 288 289 290 291 292 294 295 Columns 233 through 261 296 297 298 299 300 301 302 303 304 305 306 308 309 310 312 314 315 316 318 319 320 321 322 323 324 325 326 327 328 Columns 262 through 290 329 330 332 333 334 335 336 338 339 340 341 342 343 344 345 346 348 350 351 352 354 355 356 357 358 360 361 362 363 Columns 291 through 319 364 365 366 368 369 370 371 372 374 375 376 377 378 380 381 382 384 385 386 387 388 390 391 392 393 394 395 396 398 Columns 320 through 348 399 400 402 403 404 405 406 407 408 410 411 412 413 414 415 416 417 418 420 422 423 424 425 426 427 428 429 430 432 Columns 349 through 377 434 435 436 437 438 440 441 442 444 445 446 447 448 450 451 452 453 454 455 456 458 459 460 462 464 465 466 468 469 Columns 378 through 404 470 471 472 473 474 475 476 477 478 480 481 482 483 484 485 486 488 489 490 492 493 494 495 496 497 498 500

4   Pass
n = 50011; c = composites(n); len_correct = 44877; c_correct8900 = [10146 20070 29942 39782 49594]; assert(isequal(length(c),len_correct) && isequal(c(8900:8900:end),c_correct8900))

ans = Columns 1 through 14 4 6 8 9 10 12 14 15 16 18 20 21 22 24 Columns 15 through 28 25 26 27 28 30 32 33 34 35 36 38 39 40 42 Columns 29 through 42 44 45 46 48 49 50 51 52 54 55 56 57 58 60 Columns 43 through 56 62 63 64 65 66 68 69 70 72 74 75 76 77 78 Columns 57 through 70 80 81 82 84 85 86 87 88 90 91 92 93 94 95 Columns 71 through 84 96 98 99 100 102 104 105 106 108 110 111 112 114 115 Columns 85 through 98 116 117 118 119 120 121 122 123 124 125 126 128 129 130 Columns 99 through 112 132 133 134 135 136 138 140 141 142 143 144 145 146 147 Columns 113 through 126 148 150 152 153 154 155 156 158 159 160 161 162 164 165 Columns 127 through 140 166 168 169 170 171 172 174 175 176 177 178 180 182 183 Columns 141 through 154 184 185 186 187 188 189 190 192 194 195 196 198 200 201 Columns 155 through 168 202 203 204 205 206 207 208 209 210 212 213 214 215 216 Columns 169 through 182 217 218 219 220 221 222 224 225 226 228 230 231 232 234 Columns 183 through 196 235 236 237 238 240 242 243 244 245 246 247 248 249 250 Columns 197 through 210 252 253 254 255 256 258 259 260 261 262 264 265 266 267 Columns 211 through 224 268 270 272 273 274 275 276 278 279 280 282 284 285 286 Columns 225 through 238 287 288 289 290 291 292 294 295 296 297 298 299 300 301 Columns 239 through 252 302 303 304 305 306 308 309 310 312 314 315 316 318 319 Columns 253 through 266 320 321 322 323 324 325 326 327 328 329 330 332 333 334 Columns 267 through 280 335 336 338 339 340 341 342 343 344 345 346 348 350 351 Columns 281 through 294 352 354 355 356 357 358 360 361 362 363 364 365 366 368 Columns 295 through 308 369 370 371 372 374 375 376 377 378 380 381 382 384 385 Columns 309 through 322 386 387 388 390 391 392 393 394 395 396 398 399 400 402 Columns 323 through 336 403 404 405 406 407 408 410 411 412 413 414 415 416 417 Columns 337 through 350 418 420 422 423 424 425 426 427 428 429 430 432 434 435 Columns 351 through 364 436 437 438 440 441 442 444 445 446 447 448 450 451 452 Columns 365 through 378 453 454 455 456 458 459 460 462 464 465 466 468 469 470 Columns 379 through 392 471 472 473 474 475 476 477 478 480 481 482 483 484 485 Columns 393 through 406 486 488 489 490 492 493 494 495 496 497 498 500 501 502 Columns 407 through 420 504 505 506 507 508 510 511 512 513 514 515 516 517 518 Columns 421 through 434 519 520 522 524 525 526 527 528 529 530 531 532 533 534 Columns 435 through 448 535 536 537 538 539 540 542 543 544 545 546 548 549 550 Columns 449 through 462 551 552 553 554 555 556 558 559 560 561 562 564 565 566 Columns 463 through 476 567 568 570 572 573 574 575 576 578 579 580 581 582 583 Columns 477 through 490 584 585 586 588 589 590 591 592 594 595 596 597 598 600 Columns 491 through 504 602 603 604 605 606 608 609 610 611 612 614 615 616 618 Columns 505 through 518 620 621 622 623 624 625 626 627 628 629 630 632 633 634 Columns 519 through 532 635 636 637 638 639 640 642 644 645 646 648 649 650 651 Columns 533 through 546 652 654 655 656 657 658 660 662 663 664 665 666 667 668 Columns 547 through 560 669 670 671 672 674 675 676 678 679 680 681 682 684 685 Columns 561 through 574 686 687 688 689 690 692 693 694 695 696 697 698 699 700 Columns 575 through 588 702 703 704 705 706 707 708 710 711 712 713 714 715 716 Columns 589 through 602 717 718 720 721 722 723 724 725 726 728 729 730 731 732 Columns 603 through 616 734 735 736 737 738 740 741 742 744 745 746 747 748 749 Columns 617 through 630 750 752 753 754 755 756 758 759 760 762 763 764 765 766 Columns 631 through 644 767 768 770 771 772 774 775 776 777 778 779 780 781 782 Columns 645 through 658 783 784 785 786 788 789 790 791 792 793 794 795 796 798 Columns 659 through 672 799 800 801 802 803 804 805 806 807 808 810 812 813 814 Columns 673 through 686 815 816 817 818 819 820 822 824 825 826 828 830 831 832 Columns 687 through 700 833 834 835 836 837 838 840 841 842 843 844 845 846 847 Columns 701 through 714 848 849 850 851 852 854 855 856 858 860 861...

5   Pass
n = 3628800; c = composites(n); len_correct = 3370110; c_correct670000 = [728682 1450680 2170682 2889408 3607220]; assert(isequal(length(c),len_correct) && isequal(c(670000:670000:end),c_correct670000))

ans = Columns 1 through 14 4 6 8 9 10 12 14 15 16 18 20 21 22 24 Columns 15 through 28 25 26 27 28 30 32 33 34 35 36 38 39 40 42 Columns 29 through 42 44 45 46 48 49 50 51 52 54 55 56 57 58 60 Columns 43 through 56 62 63 64 65 66 68 69 70 72 74 75 76 77 78 Columns 57 through 70 80 81 82 84 85 86 87 88 90 91 92 93 94 95 Columns 71 through 84 96 98 99 100 102 104 105 106 108 110 111 112 114 115 Columns 85 through 98 116 117 118 119 120 121 122 123 124 125 126 128 129 130 Columns 99 through 112 132 133 134 135 136 138 140 141 142 143 144 145 146 147 Columns 113 through 126 148 150 152 153 154 155 156 158 159 160 161 162 164 165 Columns 127 through 140 166 168 169 170 171 172 174 175 176 177 178 180 182 183 Columns 141 through 154 184 185 186 187 188 189 190 192 194 195 196 198 200 201 Columns 155 through 168 202 203 204 205 206 207 208 209 210 212 213 214 215 216 Columns 169 through 182 217 218 219 220 221 222 224 225 226 228 230 231 232 234 Columns 183 through 196 235 236 237 238 240 242 243 244 245 246 247 248 249 250 Columns 197 through 210 252 253 254 255 256 258 259 260 261 262 264 265 266 267 Columns 211 through 224 268 270 272 273 274 275 276 278 279 280 282 284 285 286 Columns 225 through 238 287 288 289 290 291 292 294 295 296 297 298 299 300 301 Columns 239 through 252 302 303 304 305 306 308 309 310 312 314 315 316 318 319 Columns 253 through 266 320 321 322 323 324 325 326 327 328 329 330 332 333 334 Columns 267 through 280 335 336 338 339 340 341 342 343 344 345 346 348 350 351 Columns 281 through 294 352 354 355 356 357 358 360 361 362 363 364 365 366 368 Columns 295 through 308 369 370 371 372 374 375 376 377 378 380 381 382 384 385 Columns 309 through 322 386 387 388 390 391 392 393 394 395 396 398 399 400 402 Columns 323 through 336 403 404 405 406 407 408 410 411 412 413 414 415 416 417 Columns 337 through 350 418 420 422 423 424 425 426 427 428 429 430 432 434 435 Columns 351 through 364 436 437 438 440 441 442 444 445 446 447 448 450 451 452 Columns 365 through 378 453 454 455 456 458 459 460 462 464 465 466 468 469 470 Columns 379 through 392 471 472 473 474 475 476 477 478 480 481 482 483 484 485 Columns 393 through 406 486 488 489 490 492 493 494 495 496 497 498 500 501 502 Columns 407 through 420 504 505 506 507 508 510 511 512 513 514 515 516 517 518 Columns 421 through 434 519 520 522 524 525 526 527 528 529 530 531 532 533 534 Columns 435 through 448 535 536 537 538 539 540 542 543 544 545 546 548 549 550 Columns 449 through 462 551 552 553 554 555 556 558 559 560 561 562 564 565 566 Columns 463 through 476 567 568 570 572 573 574 575 576 578 579 580 581 582 583 Columns 477 through 490 584 585 586 588 589 590 591 592 594 595 596 597 598 600 Columns 491 through 504 602 603 604 605 606 608 609 610 611 612 614 615 616 618 Columns 505 through 518 620 621 622 623 624 625 626 627 628 629 630 632 633 634 Columns 519 through 532 635 636 637 638 639 640 642 644 645 646 648 649 650 651 Columns 533 through 546 652 654 655 656 657 658 660 662 663 664 665 666 667 668 Columns 547 through 560 669 670 671 672 674 675 676 678 679 680 681 682 684 685 Columns 561 through 574 686 687 688 689 690 692 693 694 695 696 697 698 699 700 Columns 575 through 588 702 703 704 705 706 707 708 710 711 712 713 714 715 716 Columns 589 through 602 717 718 720 721 722 723 724 725 726 728 729 730 731 732 Columns 603 through 616 734 735 736 737 738 740 741 742 744 745 746 747 748 749 Columns 617 through 630 750 752 753 754 755 756 758 759 760 762 763 764 765 766 Columns 631 through 644 767 768 770 771 772 774 775 776 777 778 779 780 781 782 Columns 645 through 658 783 784 785 786 788 789 790 791 792 793 794 795 796 798 Columns 659 through 672 799 800 801 802 803 804 805 806 807 808 810 812 813 814 Columns 673 through 686 815 816 817 818 819 820 822 824 825 826 828 830 831 832 Columns 687 through 700 833 834 835 836 837 838 840 841 842 843 844 845 846 847 Columns 701 through 714 848 849 850 851 852 854 855 856 858 860 861...

Suggested Problems

More from this Author50

Community Treasure Hunt

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

Start Hunting!