Data Structures & AlgorithmsHardGATE CS · ICPC regional
How many pairs (i, j) with 1 ≤ i ≤ j ≤ 12 have lcm(i, j) ≤ 12?
- A. 39
- B. 43
- C. 36
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Coins of values 1, 4, 9 and 16 are available in unlimited supply. What is the minimum number of coins that makes exactly 27?
- What is the maximum sum of a contiguous subarray of [4, -3, 5, 2, -7, 6, 1, 3] whose length is ODD?
- How many contiguous subarrays of [2, 3, 5, 4, 7, 6, 9] contain EXACTLY two odd numbers?
- Among the windows of exactly 3 consecutive elements of [5, 2, 9, 1, 7, 3, 8, 4], what is the smallest window sum that is at least 15?
- How many triples (a, b, c) with a < b < c taken from the set [1, 2, 3, 4, 5, 6, 8, 10, 12] satisfy a + b = c?
- How many strings of length 5 over the alphabet {a, b, c} do NOT contain the substring "abc"?