# Finding the number of elements of a set

Let S be the set of all integers from 100 to 999 which are neither divisible by 3 nor divisible by 5. The number of elements in S is

1. 480
2. 420
3. 360
4. 240

From set theory, $|A \cup B|$, the number of elements in the set $A \cup B$, can be expressed as

$$|A \cup B| = |A| + |B| - |A \cap B|$$

You want to compute $$|S| - |A \cup B|$$

Where

\begin{align} S &= \{100 \dots999\} \; \text{and} \; |S| = 900. \\ A &= \{102, 105, 108, ..., 999\} \; \text{and} \; |A| = 300. \\ B &= \{100, 105, 110, ..., 995\} \; \text{and} \; |B| = 180. \\ A \cap B &= \{105, 120, ..., 990\} \; \text{and} \; |A \cap B| = 60. \\ \hline |A \cup B| &= 300+180 - 60 = 420.\\ |S| - |A \cup B| &= 900 - 420 =480. \end{align}

• Sir, please elaborate, how you had find cardinalities of $A, B$ and of their intersection? Jun 14 '18 at 2:50
• @AkashPatalwanshi - they are all arithmetic sequences. $n = 1+\dfrac{a_n-a_1}{d}$ Jun 14 '18 at 2:59

$900\times\frac{2}{3}\times\frac{4}{5} = 480$

Reference Inclusion–exclusion principle

Sorry, I mangled the formula and rightly picked up a down-vote. I fooled myself because it gave the right answer for 3 and 5. I am correcting it. Please see Steven Gregory's answer for the proper inclusion–exclusion treatment.

Solve[{100 <= n <= 999, ! Element[n/3, Integers], !
Element[n/5, Integers]}, n, Integers] // Length

(*  480  *)

Length@Complement[Range[100, 999],Union[Range[102, 999, 3], Range[100, 999,5]]]


(*480*)

@MrWizard 's and @OkkesDulgerci 's answers are more elegant but here's a brute force method:

s = Range[100, 999];
subset = Select[s, Not[3 Floor[#/3] == #] && Not[5 Floor[#/5] == #] &]


{101, 103, 104, 106, 107, 109, 112, 113, 116, 118, 119, 121, 122, 124, 127, 128, 131, 133, 134, 136, 137, 139, 142, 143, 146, 148, 149, 151, 152, 154, 157, 158, 161, 163, 164, 166, 167, 169, 172, 173, 176, 178, 179, 181, 182, 184, 187, 188, 191, 193, 194, 196, 197, 199, 202, 203, 206, 208, 209, 211, 212, 214, 217, 218, 221, 223, 224, 226, 227, 229, 232, 233, 236, 238, 239, 241, 242, 244, 247, 248, 251, 253, 254, 256, 257, 259, 262, 263, 266, 268, 269, 271, 272, 274, 277, 278, 281, 283, 284, 286, 287, 289, 292, 293, 296, 298, 299, 301, 302, 304, 307, 308, 311, 313, 314, 316, 317, 319, 322, 323, 326, 328, 329, 331, 332, 334, 337, 338, 341, 343, 344, 346, 347, 349, 352, 353, 356, 358, 359, 361, 362, 364, 367, 368, 371, 373, 374, 376, 377, 379, 382, 383, 386, 388, 389, 391, 392, 394, 397, 398, 401, 403, 404, 406, 407, 409, 412, 413, 416, 418, 419, 421, 422, 424, 427, 428, 431, 433, 434, 436, 437, 439, 442, 443, 446, 448, 449, 451, 452, 454, 457, 458, 461, 463, 464, 466, 467, 469, 472, 473, 476, 478, 479, 481, 482, 484, 487, 488, 491, 493, 494, 496, 497, 499, 502, 503, 506, 508, 509, 511, 512, 514, 517, 518, 521, 523, 524, 526, 527, 529, 532, 533, 536, 538, 539, 541, 542, 544, 547, 548, 551, 553, 554, 556, 557, 559, 562, 563, 566, 568, 569, 571, 572, 574, 577, 578, 581, 583, 584, 586, 587, 589, 592, 593, 596, 598, 599, 601, 602, 604, 607, 608, 611, 613, 614, 616, 617, 619, 622, 623, 626, 628, 629, 631, 632, 634, 637, 638, 641, 643, 644, 646, 647, 649, 652, 653, 656, 658, 659, 661, 662, 664, 667, 668, 671, 673, 674, 676, 677, 679, 682, 683, 686, 688, 689, 691, 692, 694, 697, 698, 701, 703, 704, 706, 707, 709, 712, 713, 716, 718, 719, 721, 722, 724, 727, 728, 731, 733, 734, 736, 737, 739, 742, 743, 746, 748, 749, 751, 752, 754, 757, 758, 761, 763, 764, 766, 767, 769, 772, 773, 776, 778, 779, 781, 782, 784, 787, 788, 791, 793, 794, 796, 797, 799, 802, 803, 806, 808, 809, 811, 812, 814, 817, 818, 821, 823, 824, 826, 827, 829, 832, 833, 836, 838, 839, 841, 842, 844, 847, 848, 851, 853, 854, 856, 857, 859, 862, 863, 866, 868, 869, 871, 872, 874, 877, 878, 881, 883, 884, 886, 887, 889, 892, 893, 896, 898, 899, 901, 902, 904, 907, 908, 911, 913, 914, 916, 917, 919, 922, 923, 926, 928, 929, 931, 932, 934, 937, 938, 941, 943, 944, 946, 947, 949, 952, 953, 956, 958, 959, 961, 962, 964, 967, 968, 971, 973, 974, 976, 977, 979, 982, 983, 986, 988, 989, 991, 992, 994, 997, 998}

Length[subset]


480

• I appreciate your patience .:) Jul 24 '17 at 16:03