Elevator Prank
InterviewTime limit1sMemory limit512 MB
Each move toggles a fixed set of buttons and costs N, N/2, N/2, or N/3 seconds; count the distinct button states reachable with total time at most m, including pressing nothing.
- Level
Medium6 of 10
- Topics
- Bit manipulation, Brute force, Math, Implementation
- Solved
- No attempts yet
Problem
The elevator in building R has buttons for floors 1 through . Semteo wants to prank it by mashing the buttons. A professor is walking toward him with a grim face. A quick estimate of the professor's speed says he arrives in seconds, so Semteo decides to press as many buttons as he can within those seconds and then run.
Pressing buttons with no plan is no fun, so Semteo settles on these four moves and uses nothing else.
- Move 1: press every button from 1 to .
- Move 2: press every even numbered button.
- Move 3: press every odd numbered button.
- Move 4: press every button whose number leaves remainder 1 when divided by 3, that is buttons 1, 4, 7, ..., .
Semteo must finish a move completely before he runs or starts another move. He may also run without doing anything.
Pressing one button takes 1 second. Every button is off at the start. Pressing an off button turns it on, and pressing an on button turns it off. Count how many different button states the professor can see when Semteo presses buttons for at most seconds and then runs. Assume the elevator never moves.
Input
The first line contains two integers () and (), separated by a space.
Output
Print the number of possible final button states on the first line.
Hint
For and the possible final states are all buttons off, all buttons on, only the even buttons on, only the odd buttons on, only buttons 1, 4, 7, 10 on, only buttons 1, 2, 6, 7, 8 on, and only buttons 3, 4, 5, 9, 10 on, which is 7 states.