Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
How many ordered pairs (i, j) with 1 <= i, j <= 20 have i^2 + j^2 divisible by 5?
- A. 148
- B. 136
- C. 144
- D. 156
Correct answer: C. 144
Squares are 0, 1 or 4 mod 5, and the only residue pairs summing to 0 mod 5 are (0,0), (1,4) and (4,1). Counting residue classes avoids enumerating pairs.
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
- How many integers x with 1 <= x <= 600 are divisible by 4 or 6 but not by 12?
- How many contiguous subarrays of [6, 12, 18, 8, 4] have gcd exactly equal to 2?
- What is the least common multiple of the integers 2 through 20, reduced modulo 1000000007?
- How many contiguous subarrays of [2, 5, 3, 4, 10] have a product divisible by 10?
- How many integers from 1 to 1000 have digit sum exactly 10 and are odd?
- How many ordered pairs (a, b) with 1 <= a, b <= 6 satisfy a b ≡ 1 (mod 7)?