Question

The number of integers between 1 and 500 (both inclusive) that are divisible by 3 or 5 or 7 is ______.

Official answer and solution
Official answer
271
From
Official GATE 2017 answer key

Solution

Apply the Principle of Inclusion-Exclusion to count integers between 1 and 500 divisible by 3, 5, or 7.

Let U={1,2,…,500}U = \{1, 2, \dots, 500\}, so ∣U∣=500|U| = 500.
Let A,B,CA, B, C be the subsets of UU containing integers divisible by 3, 5, and 7 respectively.

Calculate the size of each subset:

∣A∣=⌊500/3⌋=166|A| = \lfloor 500 / 3 \rfloor = 166
∣B∣=⌊500/5⌋=100|B| = \lfloor 500 / 5 \rfloor = 100
∣C∣=⌊500/7⌋=71|C| = \lfloor 500 / 7 \rfloor = 71

Calculate the pairwise intersections using least common multiples:

  • lcm(3,5)=15  ⟹  ∣A∩B∣=⌊500/15⌋=33\text{lcm}(3, 5) = 15 \implies |A \cap B| = \lfloor 500 / 15 \rfloor = 33
  • lcm(3,7)=21  ⟹  ∣A∩C∣=⌊500/21⌋=23\text{lcm}(3, 7) = 21 \implies |A \cap C| = \lfloor 500 / 21 \rfloor = 23
  • lcm(5,7)=35  ⟹  ∣B∩C∣=⌊500/35⌋=14\text{lcm}(5, 7) = 35 \implies |B \cap C| = \lfloor 500 / 35 \rfloor = 14

Calculate the three-way intersection:

lcm(3,5,7)=105  ⟹  ∣A∩B∩C∣=⌊500/105⌋=4\text{lcm}(3, 5, 7) = 105 \implies |A \cap B \cap C| = \lfloor 500 / 105 \rfloor = 4

Applying the Principle of Inclusion-Exclusion:

∣A∪B∪C∣=(∣A∣+∣B∣+∣C∣)−(∣A∩B∣+∣A∩C∣+∣B∩C∣)+∣A∩B∩C∣|A \cup B \cup C| = (|A| + |B| + |C|) - (|A \cap B| + |A \cap C| + |B \cap C|) + |A \cap B \cap C|
∣A∪B∪C∣=(166+100+71)−(33+23+14)+4=337−70+4=271|A \cup B \cup C| = (166 + 100 + 71) - (33 + 23 + 14) + 4 = 337 - 70 + 4 = 271
Final answer

271.0

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2017 Computer Science and Information Technology (CS) Session 1
Question
47 of 65, printed as CS Q.47
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.