Available question text
Given nums up to 1e5 elements with values ≤ 5e4, compute how many pairs have each possible gcd value by counting numbers divisible by d and using inclusion–exclusion over multiples (sieve-like subtraction) to get exact pair counts for each gcd, then build cumulative counts and binary-search/map queries to the sorted gcd-pairs array. This avoids enumerating all O(n^2) pairs by leveraging divisor counting and prefix sums.
Related questions
Continue with questions that share topics or the same question type.
- Best Sightseeing Pair
Coding
- Block Placement Queries
Coding · Array · Binary Indexed Tree · Binary Search
- Check If a Number Is Majority Element in a Sorted Array
Coding
- Check if Array Is Sorted and Rotated
Coding
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 3312. Sorted GCD Pair Queries
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source