Data Structures & AlgorithmsHardICPC regional · GATE CS
Problem: Calculate the number of ordered pairs (x, y) of integers with 1 ≤ x, y ≤ 20 for which x² + y² is divisible by 5.
- A. 74
- B. 16
- C. 80
- D. 144
Correct answer: D. 144
Squares mod 5 are 0, 1, 4; pairs with both ≡ 0 (4 × 4 = 16) or residues {1, 4} (2 × 8 × 8 = 128) give 144. Unordered pairs give 74, both multiples of 5 gives only 16, and one fifth of 400 is 80.
More Coding Interview Problems questions
- Problem: A lattice path goes from (0,0) to (3,3) using steps right (1,0) and up (0,1), and it must never go above the diagonal (that is…
- Problem: The array [1, 2, 4, 8, 16, 32] stores powers of two. For how many pairs (i < j) is a[i] + a[j] a power of two?
- Problem: A queue of 5 customers arrives with service times 4, 2, 6, 1, 3. A single server processes them in order (first come first…
- Problem: Starting with the list [3, 8, 2, 5], repeatedly take the last two elements, replace them by their difference (larger minus…
- Problem: How many 3-digit numbers (100–999) have digits that form a strictly increasing sequence when read left to right?
- Problem: In a list of the first 30 positive integers, how many numbers are multiples of 2 or 3 but not of 6?