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?
  1. A. 4
  2. B. 5
  3. C. 6
  4. 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

Exams that ask this topic