CF1644F.Basis

省选/NOI-

通过率:0%

时间限制:6.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

For an array of integers aa, let's define ∣a∣|a| as the number of elements in it.

Let's denote two functions:

  • F(a,k)F(a, k) is a function that takes an array of integers aa and a positive integer kk. The result of this function is the array containing ∣a∣|a| first elements of the array that you get by replacing each element of aa with exactly kk copies of that element.

    For example, F([2,2,1,3,5,6,8],2)F([2, 2, 1, 3, 5, 6, 8], 2) is calculated as follows: first, you replace each element of the array with 22 copies of it, so you obtain [2,2,2,2,1,1,3,3,5,5,6,6,8,8][2, 2, 2, 2, 1, 1, 3, 3, 5, 5, 6, 6, 8, 8]. Then, you take the first 77 elements of the array you obtained, so the result of the function is [2,2,2,2,1,1,3][2, 2, 2, 2, 1, 1, 3].

  • G(a,x,y)G(a, x, y) is a function that takes an array of integers aa and two different integers xx and yy. The result of this function is the array aa with every element equal to xx replaced by yy, and every element equal to yy replaced by xx.

    For example, G([1,1,2,3,5],3,1)=[3,3,2,1,5]G([1, 1, 2, 3, 5], 3, 1) = [3, 3, 2, 1, 5].

An array aa is a parent of the array bb if:

  • either there exists a positive integer kk such that F(a,k)=bF(a, k) = b;
  • or there exist two different integers xx and yy such that G(a,x,y)=bG(a, x, y) = b.

An array aa is an ancestor of the array bb if there exists a finite sequence of arrays c0,c1,…,cmc_0, c_1, \dots, c_m (m≥0m \ge 0) such that c0c_0 is aa, cmc_m is bb, and for every i∈[1,m]i \in [1, m], ci−1c_{i-1} is a parent of cic_i.

And now, the problem itself.

You are given two integers nn and kk. Your goal is to construct a sequence of arrays s1,s2,…,sms_1, s_2, \dots, s_m in such a way that:

  • every array sis_i contains exactly nn elements, and all elements are integers from 11 to kk;
  • for every array aa consisting of exactly nn integers from 11 to kk, the sequence contains at least one array sis_i such that sis_i is an ancestor of aa.

Print the minimum number of arrays in such sequence.

对于一个整数数组 aa,定义 ∣a∣|a| 为其元素个数。

我们定义两个函数:

  • F(a,k)F(a, k) 是一个以整数数组 aa 和正整数 kk 为输入的函数。该函数的结果是一个长度为 ∣a∣|a| 的数组,其元素为:将 aa 中每个元素各自替换为恰好 kk 个该元素后所得新数组的前 ∣a∣|a| 个元素。

    例如,计算 F([2,2,1,3,5,6,8],2)F([2, 2, 1, 3, 5, 6, 8], 2) 的过程如下:首先将原数组中每个元素替换为 22 个该元素,得到 [2,2,2,2,1,1,3,3,5,5,6,6,8,8][2, 2, 2, 2, 1, 1, 3, 3, 5, 5, 6, 6, 8, 8];然后取该结果数组的前 77 个元素(因为原数组长度 ∣a∣=7|a|=7),因此函数结果为 [2,2,2,2,1,1,3][2, 2, 2, 2, 1, 1, 3]。

  • G(a,x,y)G(a, x, y) 是一个以整数数组 aa 和两个互异整数 xx、yy 为输入的函数。该函数的结果是将数组 aa 中所有等于 xx 的元素替换为 yy,同时将所有等于 yy 的元素替换为 xx 后所得的数组。

    例如,G([1,1,2,3,5],3,1)=[3,3,2,1,5]G([1, 1, 2, 3, 5], 3, 1) = [3, 3, 2, 1, 5]。

称数组 aa 是数组 bb 的父数组(parent),当且仅当满足以下任一条件:

  • 存在某个正整数 kk,使得 F(a,k)=bF(a, k) = b;
  • 或存在两个互异整数 xx 和 yy,使得 G(a,x,y)=bG(a, x, y) = b。

称数组 aa 是数组 bb 的祖先数组(ancestor),当且仅当存在一个有限数组序列 c0,c1,…,cmc_0, c_1, \dots, c_m(其中 m≥0m \ge 0),满足 c0=ac_0 = a,cm=bc_m = b,且对每个 i∈[1,m]i \in [1, m],均有 ci−1c_{i-1} 是 cic_i 的父数组。

现在,正式提出本题问题:

给定两个整数 nn 和 kk,你的目标是构造一个数组序列 s1,s2,…,sms_1, s_2, \dots, s_m,使得:

  • 每个数组 sis_i 恰好包含 nn 个元素,且所有元素均为 11 到 kk 之间的整数;
  • 对任意一个由恰好 nn 个取自 11 到 kk 的整数构成的数组 aa,该序列中至少存在一个数组 sis_i,使得 sis_i 是 aa 的祖先数组。

请输出满足上述条件的序列的最小可能数组个数(即最小的 mm)。

输入格式

The only line contains two integers nn and kk (1≤n,k≤2⋅1051 \le n, k \le 2 \cdot 10^5).

唯一一行包含两个整数 nn 和 kk(1≤n,k≤2⋅1051 \le n, k \le 2 \cdot 10^5)。

输出格式

Print one integer — the minimum number of elements in a sequence of arrays meeting the constraints. Since the answer can be large, output it modulo 998244353998244353.

输出一个整数——满足约束条件的数组序列中元素的最少个数。由于答案可能很大,请对 998244353998244353 取模后输出。

输入输出样例

  • 输入#1

    3 2

    输出#1

    2
  • 输入#2

    4 10

    输出#2

    12
  • 输入#3

    13 37

    输出#3

    27643508
  • 输入#4

    1337 42

    输出#4

    211887828
  • 输入#5

    198756 123456

    输出#5

    159489391
  • 输入#6

    123456 198756

    输出#6

    460526614

说明/提示

Let's analyze the first example.

One of the possible answers for the first example is the sequence [[2,1,2],[1,2,2]][[2, 1, 2], [1, 2, 2]]. Every array of size 33 consisting of elements from 11 to 22 has an ancestor in this sequence:

  • for the array [1,1,1][1, 1, 1], the ancestor is [1,2,2][1, 2, 2]: F([1,2,2],13)=[1,1,1]F([1, 2, 2], 13) = [1, 1, 1];
  • for the array [1,1,2][1, 1, 2], the ancestor is [1,2,2][1, 2, 2]: F([1,2,2],2)=[1,1,2]F([1, 2, 2], 2) = [1, 1, 2];
  • for the array [1,2,1][1, 2, 1], the ancestor is [2,1,2][2, 1, 2]: G([2,1,2],1,2)=[1,2,1]G([2, 1, 2], 1, 2) = [1, 2, 1];
  • for the array [1,2,2][1, 2, 2], the ancestor is [1,2,2][1, 2, 2];
  • for the array [2,1,1][2, 1, 1], the ancestor is [1,2,2][1, 2, 2]: G([1,2,2],1,2)=[2,1,1]G([1, 2, 2], 1, 2) = [2, 1, 1];
  • for the array [2,1,2][2, 1, 2], the ancestor is [2,1,2][2, 1, 2];
  • for the array [2,2,1][2, 2, 1], the ancestor is [2,1,2][2, 1, 2]: F([2,1,2],2)=[2,2,1]F([2, 1, 2], 2) = [2, 2, 1];
  • for the array [2,2,2][2, 2, 2], the ancestor is [1,2,2][1, 2, 2]: G(F([1,2,2],4),1,2)=G([1,1,1],1,2)=[2,2,2]G(F([1, 2, 2], 4), 1, 2) = G([1, 1, 1], 1, 2) = [2, 2, 2].

我们来分析第一个例子。

第一个例子的一个可能答案是序列 [[2,1,2],[1,2,2]][[2, 1, 2], [1, 2, 2]]。每个由 11 到 22 中的元素构成、长度为 33 的数组,在该序列中均存在一个祖先:

  • 对于数组 [1,1,1][1, 1, 1],其祖先是 [1,2,2][1, 2, 2]:F([1,2,2],13)=[1,1,1]F([1, 2, 2], 13) = [1, 1, 1];
  • 对于数组 [1,1,2][1, 1, 2],其祖先是 [1,2,2][1, 2, 2]:F([1,2,2],2)=[1,1,2]F([1, 2, 2], 2) = [1, 1, 2];
  • 对于数组 [1,2,1][1, 2, 1],其祖先是 [2,1,2][2, 1, 2]:G([2,1,2],1,2)=[1,2,1]G([2, 1, 2], 1, 2) = [1, 2, 1];
  • 对于数组 [1,2,2][1, 2, 2],其祖先是 [1,2,2][1, 2, 2];
  • 对于数组 [2,1,1][2, 1, 1],其祖先是 [1,2,2][1, 2, 2]:G([1,2,2],1,2)=[2,1,1]G([1, 2, 2], 1, 2) = [2, 1, 1];
  • 对于数组 [2,1,2][2, 1, 2],其祖先是 [2,1,2][2, 1, 2];
  • 对于数组 [2,2,1][2, 2, 1],其祖先是 [2,1,2][2, 1, 2]:F([2,1,2],2)=[2,2,1]F([2, 1, 2], 2) = [2, 2, 1];
  • 对于数组 [2,2,2][2, 2, 2],其祖先是 [1,2,2][1, 2, 2]:G(F([1,2,2],4),1,2)=G([1,1,1],1,2)=[2,2,2]G(F([1, 2, 2], 4), 1, 2) = G([1, 1, 1], 1, 2) = [2, 2, 2]。

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

首页