Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many integers from 1 to 100 inclusive are perfect squares or perfect cubes?

  1. A. 14
  2. B. 12
  3. C. 4
  4. D. 2

Correct answer: B. 12

Squares ≤ 100: 10; cubes: 4 (1, 8, 27, 64); both (sixth powers): 1 and 64. Inclusion–exclusion gives 10 + 4 − 2 = 12. Ignoring the overlap gives 14, 4 counts only the cubes and 2 only the overlap.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic