Data Structures & AlgorithmsHardCodeforces Div2 B · counting

Problem: How many ordered pairs (x, y) with 1 <= x, y <= 10 have x y <= 10? Run the code.

Problem: How many ordered pairs (x, y) with 1 <= x, y <= 10 have x * y <= 10? Run the code.
print(sum(1 for x in range(1, 11) for y in range(1, 11) if x * y <= 10))
What is printed?
  1. A. 25
  2. B. 30
  3. C. 24
  4. D. 27

Correct answer: D. 27

For each x the count is floor(10 / x), giving 10 + 5 + 3 + 2 + 2 + 1 + 1 + 1 + 1 + 1 = 27.

More Coding Interview Problems questions

Exams that ask this topic