Tap here to switch tabs
Problem
Submissions

Problem: Bulb Switcher II

med
30 min
Try to solve the Bulb Switcher II problem.

Statement

There is a room with n bulbs labeled from 11 to n, all initially turned on. You are also given four buttons that can perform the following operations:

  • Button 11: Flips the state of all bulbs.

  • Button 22: Flips the state of bulbs with even labels (i.e., 2,4,6,…2, 4, 6, \dots).

  • Button 33: Flips the state of bulbs with odd labels (i.e., 1,3,5,…1, 3, 5, \dots).

  • Button 44: Flips the state of bulbs with labels of the form 3k+13k + 1 for k≥0k \geq 0 (i.e., 1,4,7,10,…1, 4, 7, 10, \dots).

Given the two integers n and presses, return the number of distinct possible configurations of all n bulbs after pressing any of the buttons exactly presses times.

Constraints:

  • 1≤1 \leq n ≤1000\leq 1000

  • 0≤0 \leq presses ≤1000\leq 1000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Bulb Switcher II

med
30 min
Try to solve the Bulb Switcher II problem.

Statement

There is a room with n bulbs labeled from 11 to n, all initially turned on. You are also given four buttons that can perform the following operations:

  • Button 11: Flips the state of all bulbs.

  • Button 22: Flips the state of bulbs with even labels (i.e., 2,4,6,…2, 4, 6, \dots).

  • Button 33: Flips the state of bulbs with odd labels (i.e., 1,3,5,…1, 3, 5, \dots).

  • Button 44: Flips the state of bulbs with labels of the form 3k+13k + 1 for k≥0k \geq 0 (i.e., 1,4,7,10,…1, 4, 7, 10, \dots).

Given the two integers n and presses, return the number of distinct possible configurations of all n bulbs after pressing any of the buttons exactly presses times.

Constraints:

  • 1≤1 \leq n ≤1000\leq 1000

  • 0≤0 \leq presses ≤1000\leq 1000