Connection Status:
Competition Arena > Indivisible
TCCC05 Wildcard · 2005-01-10 · by vorthys · Greedy
Class Name: Indivisible
Return Type: int[]
Method Name: largestSubset
Arg Types: (int)
Problem Statement

Problem Statement

Given a positive integer n, you are to find the largest subset S of {1,...,n} such that no member of S is divisible by another member of S. If there is more than one subset of the maximum size, choose the lexicographically earliest such subset. A subset S is lexicographically earlier than a subset T if the smallest element that is a member of one of the subsets, but not both, is a member of S. Return the subset S as a int[] in increasing order.

Constraints

  • n is between 1 and 1000, inclusive.
Examples
0)
10
Returns: {4, 5, 6, 7, 9 }

There are several possible subsets of size 5, such as { 4,6,7,9,10 }, but { 4,5,6,7,9 } is the lexicographically earliest.

1)
20
Returns: {4, 6, 7, 9, 10, 11, 13, 15, 17, 19 }
2)
100
Returns: {16, 20, 24, 26, 28, 30, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 49, 50, 51, 53, 54, 55, 57, 58, 59, 61, 62, 63, 65, 66, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99 }
3)
1000
Returns: {64, 80, 96, 104, 112, 120, 136, 144, 152, 156, 164, 168, 172, 176, 180, 184, 188, 196, 200, 204, 212, 216, 220, 226, 228, 230, 232, 234, 236, 238, 242, 244, 246, 248, 250, 252, 254, 258, 260, 262, 264, 266, 268, 270, 274, 276, 278, 280, 282, 284, 286, 290, 292, 294, 296, 298, 300, 302, 306, 308, 310, 314, 316, 318, 322, 324, 326, 330, 332, 334, 335, 337, 338, 339, 340, 341, 342, 343, 345, 346, 347, 348, 349, 350, 351, 353, 354, 355, 356, 357, 358, 359, 361, 362, 363, 364, 365, 366, 367, 369, 370, 371, 372, 373, 374, 375, 377, 378, 379, 380, 381, 382, 383, 385, 386, 387, 388, 389, 390, 391, 393, 394, 395, 396, 397, 398, 399, 401, 402, 403, 404, 405, 406, 407, 409, 410, 411, 412, 413, 414, 415, 417, 418, 419, 420, 421, 422, 423, 425, 426, 427, 428, 429, 430, 431, 433, 434, 435, 436, 437, 438, 439, 441, 442, 443, 444, 445, 446, 447, 449, 450, 451, 453, 454, 455, 457, 458, 459, 461, 462, 463, 465, 466, 467, 469, 470, 471, 473, 474, 475, 477, 478, 479, 481, 482, 483, 485, 486, 487, 489, 490, 491, 493, 494, 495, 497, 498, 499, 501, 502, 503, 505, 506, 507, 509, 510, 511, 513, 514, 515, 517, 518, 519, 521, 522, 523, 525, 526, 527, 529, 530, 531, 533, 534, 535, 537, 538, 539, 541, 542, 543, 545, 546, 547, 549, 550, 551, 553, 554, 555, 557, 558, 559, 561, 562, 563, 565, 566, 567, 569, 570, 571, 573, 574, 575, 577, 578, 579, 581, 582, 583, 585, 586, 587, 589, 590, 591, 593, 594, 595, 597, 598, 599, 601, 602, 603, 605, 606, 607, 609, 610, 611, 613, 614, 615, 617, 618, 619, 621, 622, 623, 625, 626, 627, 629, 630, 631, 633, 634, 635, 637, 638, 639, 641, 642, 643, 645, 646, 647, 649, 650, 651, 653, 654, 655, 657, 658, 659, 661, 662, 663, 665, 666, 667, 669, 671, 673, 675, 677, 679, 681, 683, 685, 687, 689, 691, 693, 695, 697, 699, 701, 703, 705, 707, 709, 711, 713, 715, 717, 719, 721, 723, 725, 727, 729, 731, 733, 735, 737, 739, 741, 743, 745, 747, 749, 751, 753, 755, 757, 759, 761, 763, 765, 767, 769, 771, 773, 775, 777, 779, 781, 783, 785, 787, 789, 791, 793, 795, 797, 799, 801, 803, 805, 807, 809, 811, 813, 815, 817, 819, 821, 823, 825, 827, 829, 831, 833, 835, 837, 839, 841, 843, 845, 847, 849, 851, 853, 855, 857, 859, 861, 863, 865, 867, 869, 871, 873, 875, 877, 879, 881, 883, 885, 887, 889, 891, 893, 895, 897, 899, 901, 903, 905, 907, 909, 911, 913, 915, 917, 919, 921, 923, 925, 927, 929, 931, 933, 935, 937, 939, 941, 943, 945, 947, 949, 951, 953, 955, 957, 959, 961, 963, 965, 967, 969, 971, 973, 975, 977, 979, 981, 983, 985, 987, 989, 991, 993, 995, 997, 999 }
4)
1
Returns: {1 }

Submissions are judged against all 52 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class Indivisible with a public method vector<int> largestSubset(int n) · 52 test cases · 2 s / 256 MB per case

Submitting as anonymous