Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

How many arithmetic triples (x, x+d, x+2d) with d >= 1 consist entirely of values from [1, 2, 3, 5, 7, 9]?

  1. A. 6
  2. B. 4
  3. C. 7
  4. D. 5

Correct answer: D. 5

Fix the first term and the common difference, and check membership with a set. Each progression is counted once by its first term and difference.

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

Exams that ask this topic