Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 B
There are 100 bulbs, all off. For each i from 1 to 100, pass i toggles every bulb whose number is a multiple of i. How many bulbs are on at the end?
- A. 10
- B. 9
- C. 50
- D. 25
Correct answer: A. 10
A bulb is toggled once per divisor and stays on only with an odd number of divisors, which happens exactly for perfect squares: 1, 4, ..., 100 = 10. Forgetting 100 gives 9, 50 assumes alternate bulbs, and 25 counts primes, which are toggled twice and end off.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the smallest positive integer x such that 180 x is a perfect cube?
- How many trailing zeros does 100! have when written in base 6?
- What is the sum of all distinct prime factors of the product 12 35 49 (sum each prime once, however many times it divides the product)?
- What is the lexicographically smallest string obtainable by deleting exactly one character from cbabc?
- How many length-3 windows of the string aabxaaba have at most one position that differs from the pattern aab?
- How many binary strings of length 6 contain no two consecutive 1s?