atcoder#ABC300H. [ABC300Ex] Fibonacci: Revisited

[ABC300Ex] Fibonacci: Revisited

Score : 600600 points

Problem Statement

We define the general term ana_n of a sequence a0,a1,a2,a_0, a_1, a_2, \dots 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 NN, find the sum, modulo 998244353998244353, of ama_m over all non-negative integers mm such that m AND N=mm\text{ AND }N = m. (AND\text{AND} denotes the bitwise AND.)

What is bitwise AND?

The bitwise AND of non-negative integers A and B, A\text{ AND }B, is defined as follows.

・When A\text{ AND }B is written in binary, its 2^ks place (k \geq 0) is 1 if 2^ks places of A and B are both 1, and 0 otherwise.

Constraints

  • 1K5×1041 \leq K \leq 5 \times 10^4
  • 0N10180 \leq N \leq 10^{18}
  • NN and KK are integers.

Input

The input is given from Standard Input in the following format:

KK NN

Output

Print the answer.

2 6
21

a0a_0 and succeeding terms are 1,1,2,3,5,8,13,21,1, 1, 2, 3, 5, 8, 13, 21, \dots. Four non-negative integers, 0,2,40, 2, 4, and 66, satisfy 6 AND m=m6 \text{ AND } m = m, so the answer is 1+2+5+13=211 + 2 + 5 + 13 = 21.

2 8
35
1 123456789
65536
300 20230429
125461938
42923 999999999558876113
300300300