Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice
Problem: How many integer pairs (x, y) with 1 <= x <= 10 and 1 <= y <= 10 satisfy x y being a perfect cube? Run the code.
Problem: How many integer pairs (x, y) with 1 <= x <= 10 and 1 <= y <= 10 satisfy x * y being a perfect cube? Run the code.
print(sum(1 for x in range(1, 11) for y in range(1, 11) if int(round((x * y) ** (1 / 3))) ** 3 == x * y))What is printed?
- A. 5
- B. 8
- C. 4
- D. 18
Correct answer: B. 8
Cube products: (1,1), (1,8), (8,1), (2,4), (4,2), (3,9), (9,3), (8,8), so 8 ordered pairs. Unordered pairs give 5, requiring both to be cubes gives 4, and testing for squares instead gives 18.
More Coding Interview Problems questions
- Problem: What is the longest run of consecutive integers that all have at least one divisor in common with 30 (gcd greater than 1)…
- Problem: How many integers in [1, 500] are divisible by 4 or by 6 but not by 12? Run the code. python print(sum(1 for x in range(1, 501)…
- Problem: What is the sum of the first 12 terms of the sequence an = n^2 + 1 (n from 1 to 12)? Run the code. python print(sum(n n + 1 for n…
- Problem: How many 4-letter words over {x, y, z} contain at least one letter from each of the three symbols? Run the code. python from…
- Problem: What is the number of integers x in [1, 200] for which x^2 + 2x + 1 is divisible by 7? Run the code. python print(sum(1 for x in…
- Problem: How many integer solutions (x, y) satisfy x^2 + y^2 = 65 with x, y >= 0? Run the code. python print(sum(1 for x in range(0, 9)…