打卡信奥刷题(245)用Scratch图形化工具信奥P9632[普及组][ICPC2020 Nanjing R] K Co-prime Permutation

[ICPC2020 Nanjing R] K Co-prime Permutation

题面翻译

题目描述

给定两个整数 n n n k k k,构造一个 1 ∼ n 1 \sim n 1n 的排列 p 1 , p 2 , ⋯   , p n p_1,p_2,\cdots,p_n p1,p2,,pn,使得存在 k k k 个整数 i i i 满足 1 ≤ i ≤ n 1 \le i \le n 1in gcd ( p i , i ) = 1 \text{gcd}(p_i,i)=1 gcd(pi,i)=1

gcd ( x , y ) \text{gcd}(x,y) gcd(x,y) 表示 x x x y y y 的最大公约数。

输入格式

只有一组测试数据。

第一行输入两个整数 n n n k k k ( 1 ≤ n ≤ 1 0 6 , 0 ≤ k ≤ n ) (1 \le n \le 10^6, 0 \le k \le n) (1n106,0kn)

输出格式

输出一行 n n n 个整数 p 1 , p 2 , ⋯   , p n p_1, p_2, \cdots, p_n p1,p2,,pn,用空格分隔,表示一个满足给定的约束的排列。如果没有存在的排列则输出 -1。如果有多个有效的答案,输出任意一个均可。

请不要在行末输出多余的空格,否则你的答案可能会被认为是错误的。

样例 #1

样例输入 #1
5 3
样例输出 #1
1 4 5 2 3

样例 #2

样例输入 #2
1 0
样例输出 #2
-1

题目描述

Kotori is very good at math (really?) and she loves playing with permutations and primes.

One day, she thinks of a special kind of permutation named k   co-prime   permutation \textit{k co-prime permutation} k co-prime permutation. A permutation p 1 , p 2 , ⋯   , p n p_1,p_2,\cdots,p_n p1,p2,,pn of n n n is called a k k k co-prime permutation of n n n if there exists exactly k k k integers i i i such that 1 ≤ i ≤ n 1 \le i \le n 1in and gcd ( p i , i ) = 1 \text{gcd}(p_i,i)=1 gcd(pi,i)=1, where gcd ( x , y ) \text{gcd}(x,y) gcd(x,y) indicates the greatest common divisor of x x x and y y y.

Given n n n and k k k, please help Kotori construct a k k k co-prime permutation of n n n or just report that there is no such permutation.

Recall that a permutation of n n n is a sequence of length n n n containing all integers from 1 1 1 to n n n.

输入格式

There is only one test case in each test file.

The first and only line contains two integers n n n and k k k ( 1 ≤ n ≤ 1 0 6 1 \le n \le 10^6 1n106, 0 ≤ k ≤ n 0 \le k \le n 0kn).

输出格式

Output one line containing n n n integers p 1 , p 2 , ⋯   , p n p_1, p_2, \cdots, p_n p1,p2,,pn separated by one space, indicating the permutation satisfying the given constraints. If no such permutation exists output -1 (without quotes) instead. If there are multiple valid answers you can print any of them.

Please, DO NOT output extra spaces at the end of each line, otherwise your answer may be considered incorrect!

样例 #1

样例输入 #1

5 3

样例输出 #1

1 4 5 2 3

样例 #2

样例输入 #2

1 0

样例输出 #2

-1

Scratch实现

在这里插入图片描述

后续

接下来我会不断用scratch来实现信奥比赛中的算法题、Scratch考级编程题实现、白名单赛事考题实现,感兴趣的请关注,我后续将继续分享相关内容

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值