Data Structures & AlgorithmsHardCodeforces Div2 B · number theory

Problem: How many integers x in [1, 50] are perfect sixth powers (x = y^6 for an integer y)? Run the code.

Problem: How many integers x in [1, 50] are perfect sixth powers (x = y^6 for an integer y)? Run the code.
print(sum(1 for x in range(1, 51) if round(x ** (1 / 6)) ** 6 == x))
What is printed?
  1. A. 2
  2. B. 1
  3. C. 0
  4. D. 3

Correct answer: B. 1

Only 1 = 1^6 lies in range, since 2^6 = 64 is already above 50. Confusing sixth powers with cubes (8, 27) gives a wrong count.

More Coding Interview Problems questions

Exams that ask this topic