CF1758C.Almost All Multiples

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Given two integers nn and xx, a permutation†^{\dagger} pp of length nn is called funny if pip_i is a multiple of ii for all 1≤i≤n−11 \leq i \leq n - 1, pn=1p_n = 1, and p1=xp_1 = x.

Find the lexicographically minimal‡^{\ddagger} funny permutation, or report that no such permutation exists.

†^{\dagger} A permutation of length nn is an array consisting of each of the integers from 11 to nn exactly once.

‡^{\ddagger} Let aa and bb be permutations of length nn. Then aa is lexicographically smaller than bb if in the first position ii where aa and bb differ, ai<bia_i \lt b_i. A permutation is lexicographically minimal if it is lexicographically smaller than all other permutations.

给定两个整数 nn 和 xx,一个长度为 nn 的排列†^{\dagger} pp 被称为有趣的,当且仅当满足以下条件:对所有 1≤i≤n−11 \leq i \leq n - 1,pip_i 是 ii 的倍数;pn=1p_n = 1;且 p1=xp_1 = x。

请找出字典序最小的‡^{\ddagger} 有趣排列;若不存在这样的排列,则报告无解。

†^{\dagger} 长度为 nn 的排列是指由 11 到 nn 中每个整数恰好出现一次所构成的数组。

‡^{\ddagger} 设 aa 和 bb 均为长度为 nn 的排列。若在 aa 与 bb 首次不同的位置 ii 上有 ai<bia_i \lt b_i,则称 aa 的字典序小于 bb。字典序最小的排列是指其字典序严格小于所有其他(可行)排列的排列。

输入格式

The input consists of multiple test cases. The first line contains an integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases. The description of the test cases follows.

The only line of each test case contains two integers nn and xx (2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5; 1<x≤n1 \lt x \leq n).

The sum of nn across all test cases does not exceed 2⋅1052 \cdot 10^5.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例仅有一行,包含两个整数 nn 和 xx(2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5;1<x≤n1 \lt x \leq n)。

所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, if the answer exists, output nn distinct integers p1,p2,…,pnp_1, p_2, \dots, p_n (1≤pi≤n1 \leq p_i \leq n) — the lexicographically minimal funny permutation pp. Otherwise, output −1-1.

对于每个测试用例,如果答案存在,则输出 nn 个互不相同的整数 p1,p2,…,pnp_1, p_2, \dots, p_n(其中 1≤pi≤n1 \leq p_i \leq n)——即字典序最小的“有趣排列” pp;否则,输出 −1-1。

输入输出样例

  • 输入#1

    3
    3 3
    4 2
    5 4

    输出#1

    3 2 1 
    2 4 3 1 
    -1

说明/提示

In the first test case, the permutation [3,2,1][3,2,1] satisfies all the conditions: p1=3p_1=3, p3=1p_3=1, and:

  • p1=3p_1=3 is a multiple of 11.
  • p2=2p_2=2 is a multiple of 22.

In the second test case, the permutation [2,4,3,1][2,4,3,1] satisfies all the conditions: p1=2p_1=2, p4=1p_4=1, and:

  • p1=2p_1=2 is a multiple of 11.
  • p2=4p_2=4 is a multiple of 22.
  • p3=3p_3=3 is a multiple of 33.

We can show that these permutations are lexicographically minimal.

No such permutations exist in the third test case.

在第一个测试用例中,排列 [3,2,1][3,2,1] 满足所有条件:p1=3p_1=3,p3=1p_3=1,且:

  • p1=3p_1=3 是 11 的倍数。
  • p2=2p_2=2 是 22 的倍数。

在第二个测试用例中,排列 [2,4,3,1][2,4,3,1] 满足所有条件:p1=2p_1=2,p4=1p_4=1,且:

  • p1=2p_1=2 是 11 的倍数。
  • p2=4p_2=4 是 22 的倍数。
  • p3=3p_3=3 是 33 的倍数。

我们可以证明这些排列是字典序最小的。

在第三个测试用例中,不存在满足条件的排列。

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

首页