#abc300h. [abc300_h]Fibonacci: Revisited
[abc300_h]Fibonacci: Revisited
Problem Statement
We define the general term of a sequence by:
$a_n = \\begin{cases} 1 & (0 \\leq n \\lt K) \\\\ \\displaystyle{\\sum_{i=1}^K} a_{n-i} & (K \\leq n). \\\\ \\end{cases}$
Given an integer , find the sum, modulo , of over all non-negative integers such that . ( denotes the bitwise AND.)
What is bitwise AND? The bitwise AND of non-negative integers and , , is defined as follows.
・When is written in binary, its s place () is if s places of and are both , and otherwise.
Constraints
- and are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
2 6
Sample Output 1
21
and succeeding terms are . Four non-negative integers, , and , satisfy , so the answer is .
Sample Input 2
2 8
Sample Output 2
35
Sample Input 3
1 123456789
Sample Output 3
65536
Sample Input 4
300 20230429
Sample Output 4
125461938
Sample Input 5
42923 999999999558876113
Sample Output 5
300300300