Data Structures & AlgorithmsHardCAT · TCS NQT

Problem: How many integers from 1 to 500 are NOT perfect squares and NOT perfect cubes?

  1. A. 471
  2. B. 473
  3. C. 478
  4. D. 27

Correct answer: B. 473

22 squares + 7 cubes − 2 sixth powers (1, 64) = 27 are a square or cube, so 500 − 27 = 473. Not removing the overlap gives 471, removing only squares gives 478, and 27 is the excluded count.

More Coding Interview Problems questions

Exams that ask this topic