#abc276g. G - Count Sequences

G - Count Sequences

Score : 600600 points

问题陈述

找出满足以下条件的整数序列 A=(a1,a2,,aN)A=(a_1,a_2,\ldots,a_N) 的个数,对 998244353998244353 取模。

  • 0a1a2aNM0 \leq a_1 \leq a_2 \leq \ldots \leq a_N \leq M
  • 对于每个 i=1,2,,N1i=1,2,\ldots,N-1,当 aia_i 除以 33 的余数与 ai+1a_{i+1} 除以 33 的余数不相同时。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Find the number of sequences of integers with NN terms, A=(a1,a2,,aN)A=(a_1,a_2,\ldots,a_N), that satisfy the following conditions, modulo 998244353998244353.

  • 0a1a2aNM0 \leq a_1 \leq a_2 \leq \ldots \leq a_N \leq M.
  • For each i=1,2,,N1i=1,2,\ldots,N-1, the remainder when aia_i is divided by 33 is different from the remainder when ai+1a_{i+1} is divided by 33.

Constraints

  • 2N1072 \leq N \leq 10^7
  • 1M1071 \leq M \leq 10^7
  • All values in the input are integers.

Input

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

NN MM

Output

Print the answer.

Sample Input 1

3 4

Sample Output 1

8

Here are the eight sequences that satisfy the conditions.

  • (0,1,2)(0,1,2)
  • (0,1,3)(0,1,3)
  • (0,2,3)(0,2,3)
  • (0,2,4)(0,2,4)
  • (1,2,3)(1,2,3)
  • (1,2,4)(1,2,4)
  • (1,3,4)(1,3,4)
  • (2,3,4)(2,3,4)

Sample Input 2

276 10000000

Sample Output 2

909213205

Be sure to find the count modulo 998244353998244353.

update @ 2024/3/10 11:38:29