Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 B

How many index pairs i < j in [1, 2, 3, 4, 5, 6] satisfy that a[i] times a[j] equals a[i] plus a[j]?

  1. A. 1
  2. B. 2
  3. C. 4
  4. D. 0

Correct answer: D. 0

x*y = x+y is equivalent to (x-1)(y-1) = 1, which only holds for x = y = 2 or x = y = 0. Since the values are distinct, the answer is found by algebra, not by search.

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

Exams that ask this topic