Imagine you're in a room with n bulbs labeled from 1 to n, all initially turned ON. On the wall, there are four special buttons that control the bulbs in different patterns:
- Button 1: Flips all bulbs (1, 2, 3, 4, ...)
- Button 2: Flips bulbs with even labels (2, 4, 6, 8, ...)
- Button 3: Flips bulbs with odd labels (1, 3, 5, 7, ...)
- Button 4: Flips bulbs at positions
3k + 1where k โฅ 0 (1, 4, 7, 10, ...)
You must press buttons exactly presses times. Each press can be any of the four buttons. Your goal is to determine how many different possible states the bulbs can be in after all button presses.
Example: With n=2 and presses=1, you could press button 1 (both bulbs OFF), button 2 (bulb 1 ON, bulb 2 OFF), or button 3 (bulb 1 OFF, bulb 2 ON), giving you 3 different states.
Input & Output
Visualization
Time & Space Complexity
Constant time as we only check fixed number of combinations
Only store a few button states and bulb configurations
Constraints
- 1 โค n โค 1000
- 0 โค presses โค 1000
- All bulbs start in the ON state
- Button presses must be exactly equal to the given number