CF1749D.Counting Arrays

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Consider an array aa of length nn with elements numbered from 11 to nn. It is possible to remove the ii-th element of aa if gcd(ai,i)=1gcd(a_i, i) = 1, where gcdgcd denotes the greatest common divisor. After an element is removed, the elements to the right are shifted to the left by one position.

An array bb with nn integers such that 1≤bi≤n−i+11 \le b_i \le n - i + 1 is a removal sequence for the array aa if it is possible to remove all elements of aa, if you remove the b1b_1-th element, then the b2b_2-th, ..., then the bnb_n-th element. For example, let a=[42,314]a = [42, 314]:

  • [1,1][1, 1] is a removal sequence: when you remove the 11-st element of the array, the condition gcd(42,1)=1gcd(42, 1) = 1 holds, and the array becomes [314][314]; when you remove the 11-st element again, the condition gcd(314,1)=1gcd(314, 1) = 1 holds, and the array becomes empty.
  • [2,1][2, 1] is not a removal sequence: when you try to remove the 22-nd element, the condition gcd(314,2)=1gcd(314, 2) = 1 is false.

An array is ambiguous if it has at least two removal sequences. For example, the array [1,2,5][1, 2, 5] is ambiguous: it has removal sequences [3,1,1][3, 1, 1] and [1,2,1][1, 2, 1]. The array [42,314][42, 314] is not ambiguous: the only removal sequence it has is [1,1][1, 1].

You are given two integers nn and mm. You have to calculate the number of ambiguous arrays aa such that the length of aa is from 11 to nn and each aia_i is an integer from 11 to mm.

考虑一个长度为 nn 的数组 aa,其元素编号从 11 到 nn。当且仅当 gcd⁡(ai,i)=1\gcd(a_i, i) = 1(其中 gcd⁡\gcd 表示最大公约数)时,可以删除 aa 的第 ii 个元素。删除某个元素后,其右侧的所有元素均向左移动一位。

若存在一个含 nn 个整数的数组 bb,满足对所有 ii 均有 1≤bi≤n−i+11 \le b_i \le n - i + 1,且按顺序依次删除 aa 的第 b1b_1 个元素、第 b2b_2 个元素、……、第 bnb_n 个元素,最终可将 aa 的所有元素全部删除,则称 bb 是数组 aa 的一个删除序列。例如,设 a=[42,314]a = [42, 314]:

  • [1,1][1, 1] 是一个删除序列:首先删除数组中第 11 个元素,此时 gcd⁡(42,1)=1\gcd(42, 1) = 1 成立,数组变为 [314][314];再删除当前数组中第 11 个元素,此时 gcd⁡(314,1)=1\gcd(314, 1) = 1 成立,数组变为空。
  • [2,1][2, 1] 不是一个删除序列:首次尝试删除第 22 个元素时,gcd⁡(314,2)=1\gcd(314, 2) = 1 不成立。

若一个数组至少拥有两个不同的删除序列,则称该数组是歧义的(ambiguous)。例如,数组 [1,2,5][1, 2, 5] 是歧义的:它拥有两个删除序列 [3,1,1][3, 1, 1] 和 [1,2,1][1, 2, 1]。而数组 [42,314][42, 314] 不是歧义的:它唯一的删除序列是 [1,1][1, 1]。

现给定两个整数 nn 和 mm。你需要计算满足以下条件的歧义数组 aa 的个数:aa 的长度在 11 到 nn 之间(含端点),且每个元素 aia_i 均为 11 到 mm 之间的整数。

输入格式

The only line of the input contains two integers nn and mm (2≤n≤3⋅1052 \le n \le 3 \cdot 10^5; 1≤m≤10121 \le m \le 10^{12}).

输入仅包含一行,其中有两个整数 nn 和 mm(2≤n≤3⋅1052 \le n \le 3 \cdot 10^5;1≤m≤10121 \le m \le 10^{12})。

输出格式

Print one integer — the number of ambiguous arrays aa such that the length of aa is from 11 to nn and each aia_i is an integer from 11 to mm. Since the answer can be very large, print it modulo 998244353998244353.

输出一个整数——满足以下条件的模糊数组 aa 的个数:数组 aa 的长度在 11 到 nn 之间,且每个元素 aia_i 均为 11 到 mm 之间的整数。由于答案可能非常大,请对 998244353998244353 取模后输出。

输入输出样例

  • 输入#1

    2 3

    输出#1

    6
  • 输入#2

    4 2

    输出#2

    26
  • 输入#3

    4 6

    输出#3

    1494
  • 输入#4

    1337 424242424242

    输出#4

    119112628

输入解题思路,AI测评打分。不知道怎么写?

首页