QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 1024 MB 总分: 100 可 Hack ✓

#16915. 乐谱

统计

图像由 ChatGPT 4o 生成。

爱丽丝喜欢唱歌。作为一名唱歌爱好者,爱丽丝听过无数首歌,并尝试唱过很多次。然而,偶尔有些歌会让爱丽丝感到厌倦。经过一番研究,爱丽丝认为这是因为尽管她选择的歌曲各不相同,但由于她本能的偏好,它们在音乐上都彼此相似。

为了彻底分析这一点,爱丽丝决定研究这些歌曲的乐谱。为了方便起见,爱丽丝将一首长度为 $n$ 的歌曲表示为一个整数序列 $a_1, a_2, \dots, a_n$,其中 $a_i$ 是第 $i$ 个音符的音高。然后,她定义了歌曲之间的音乐等价性。如果对于所有 $1 \le i < n$,$a_i, a_{i+1}$ 与 $b_i, b_{i+1}$ 具有相同的音高关系,则称两首长度为 $n$ 的歌曲 $a_1, a_2, \dots, a_n$ 和 $b_1, b_2, \dots, b_n$ 在音乐上是等价的。更具体地说,如果满足以下条件之一,则称 $a_i, a_{i+1}$ 与 $b_i, b_{i+1}$ 具有相同的音高关系:

  • $a_i < a_{i+1}$ 且 $b_i < b_{i+1}$,
  • $a_i = a_{i+1}$ 且 $b_i = b_{i+1}$,或
  • $a_i > a_{i+1}$ 且 $b_i > b_{i+1}$。

例如,$1, 2, 3, 3, 2$ 和 $5, 9, 13, 13, 1$ 在音乐上是等价的,而 $1, 2, 3, 2, 1$ 和 $1, 2, 2, 2, 1$ 则不是。

经过长期坚持不懈的练习,爱丽丝能够演唱范围在 $[1, k]$ 内的任何音符。她想知道,如果将音乐上等价的歌曲视为同一种,那么在她的音域范围内,有多少种不同的长度为 $n$ 的歌曲?你能帮她计算这个数量吗?

由于答案可能很大,请将答案对 $998244353$ 取模后输出。

输入格式

仅包含一行,其中有两个整数 $n, k$。

输出格式

输出不同歌曲的数量对 $998244353$ 取模后的结果。

数据范围

  • $1 \le n \le 10^6$
  • $1 \le k \le 10^9$

样例

输入样例 1

3 2

输出样例 1

7

输入样例 2

5 3

输出样例 2

67

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.