Data Structures & AlgorithmsModerateCodeforces Div2 B · CRT counting
Problem: How many integers x in [1, 60] satisfy x ≡ 2 (mod 3) and x ≡ 3 (mod 4)? Run the code.
Problem: How many integers x in [1, 60] satisfy x ≡ 2 (mod 3) and x ≡ 3 (mod 4)? Run the code.
print(sum(1 for x in range(1, 61) if x % 3 == 2 and x % 4 == 3))What is printed?
- A. 4
- B. 5
- C. 6
- D. 3
Correct answer: B. 5
The conditions combine to x ≡ 11 (mod 12), giving 11, 23, 35, 47 and 59. The modulus 12 is the lcm of 3 and 4, which is why there are five solutions in [1, 60].
More Coding Interview Problems questions
- Problem: How many unordered pairs from {1, 2, 3, 4, 5, 6} have XOR equal to 7? Run the code. python from itertools import combinations…
- Problem: How many palindromic substrings of length at least 1 does 'abcba' contain? Run the code. python s = 'abcba' print(sum(1 for i in…
- Problem: What is the smallest positive integer whose decimal digits multiply to 36? Run the search code. python x = 1 while True: p = 1…
- Problem: How many ways are there to place 2 non-attacking rooks on a 3 x 3 board (distinct squares, different rows and different columns…
- Problem: How many monotone lattice paths from (0,0) to (2,2) exist on a 3 x 3 grid if the moves are right, down or diagonal (down-right)?…
- Problem: What is the sum of i (5 - i) for i from 1 to 4? Run the code. python print(sum(i (5 - i) for i in range(1, 5))) What is printed?