CF1758C.Almost All Multiples
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Given two integers n and x , a permutation † p of length n is called funny if pi is a multiple of i for all 1≤i≤n−1 , pn=1 , and p1=x .
Find the lexicographically minimal ‡ funny permutation, or report that no such permutation exists.
† A permutation of length n is an array consisting of each of the integers from 1 to n exactly once.
‡ Let a and b be permutations of length n . Then a is lexicographically smaller than b if in the first position i where a and b differ, ai<bi . A permutation is lexicographically minimal if it is lexicographically smaller than all other permutations.
输入格式
The input consists of multiple test cases. The first line contains an integer t ( 1≤t≤104 ) — the number of test cases. The description of the test cases follows.
The only line of each test case contains two integers n and x ( 2≤n≤2⋅105 ; 1<x≤n ).
The sum of n across all test cases does not exceed 2⋅105 .
输出格式
For each test case, if the answer exists, output n distinct integers p1,p2,…,pn ( 1≤pi≤n ) — the lexicographically minimal funny permutation p . Otherwise, output −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] satisfies all the conditions: p1=3 , p3=1 , and:
- p1=3 is a multiple of 1 .
- p2=2 is a multiple of 2 .
In the second test case, the permutation [2,4,3,1] satisfies all the conditions: p1=2 , p4=1 , and:
- p1=2 is a multiple of 1 .
- p2=4 is a multiple of 2 .
- p3=3 is a multiple of 3 .
We can show that these permutations are lexicographically minimal.
No such permutations exist in the third test case.