Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 B

How many pairs a < b with 1 <= a < b <= 12 satisfy gcd(a, b) = b - a?

  1. A. 24
  2. B. 25
  3. C. 23
  4. D. 27

Correct answer: C. 23

gcd(a, b) divides b - a, so the condition means gcd(a, b) equals the gap itself, which forces the gap to divide a. Enumerate the pairs whose gap divides a.

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

Exams that ask this topic