Under construction

Still being built. Things may change

Elevator Prank

Interview

Time limit1sMemory limit512 MB

Summary
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 NN. 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 mm seconds, so Semteo decides to press as many buttons as he can within those mm 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 NN.
  • 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, ..., 3k+13k+1.

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 mm seconds and then runs. Assume the elevator never moves.

Input

The first line contains two integers NN (1≤N≤1000001 \le N \le 100000) and mm (0≤m≤1000000 \le m \le 100000), separated by a space.

Output

Print the number of possible final button states on the first line.

Hint

For N=10N = 10 and m=10m = 10 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.

Examples1

  1. Example 1

    Input
    10 10
    
    Expected output
    7