Data Structures & AlgorithmsHardCAT · Codeforces Div2 B

How many integers x with 1 <= x <= 500 are divisible by exactly one of 6 and 8?

  1. A. 107
  2. B. 101
  3. C. 111
  4. D. 105

Correct answer: D. 105

Exactly one of two divisibility conditions is an XOR, so subtract the multiples of lcm(6, 8) = 24 from the union count. Counting the union alone gives the 'at least one' answer.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic