Data Structures & AlgorithmsHardGATE CS · ICPC regional

How many pairs (i, j) with 1 ≤ i ≤ j ≤ 12 have lcm(i, j) ≤ 12?

  1. A. 39
  2. B. 43
  3. C. 36
  4. D. 78

Correct answer: A. 39

Enumerate pairs with i ≤ j and check lcm(i, j) = i·j / gcd(i, j) against the bound with integer arithmetic. Counting only pairs with i·j ≤ n ignores the gcd that shrinks the lcm.

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

Exams that ask this topic