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

[ICPC2020 Nanjing R] K Co-prime Permutation

题面翻译

题目描述

给定两个整数 nnnkkk,构造一个 1∼n1 \sim n1n 的排列 p1,p2,⋯ ,pnp_1,p_2,\cdots,p_np1,p2,,pn,使得存在 kkk 个整数 iii 满足 1≤i≤n1 \le i \le n1ingcd(pi,i)=1\text{gcd}(p_i,i)=1gcd(pi,i)=1

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

输入格式

只有一组测试数据。

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

输出格式

输出一行 nnn 个整数 p1,p2,⋯ ,pnp_1, p_2, \cdots, p_np1,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 p1,p2,⋯ ,pnp_1,p_2,\cdots,p_np1,p2,,pn of nnn is called a kkk co-prime permutation of nnn if there exists exactly kkk integers iii such that 1≤i≤n1 \le i \le n1in and gcd(pi,i)=1\text{gcd}(p_i,i)=1gcd(pi,i)=1, where gcd(x,y)\text{gcd}(x,y)gcd(x,y) indicates the greatest common divisor of xxx and yyy.

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

Recall that a permutation of nnn is a sequence of length nnn containing all integers from 111 to nnn.

输入格式

There is only one test case in each test file.

The first and only line contains two integers nnn and kkk (1≤n≤1061 \le n \le 10^61n106, 0≤k≤n0 \le k \le n0kn).

输出格式

Output one line containing nnn integers p1,p2,⋯ ,pnp_1, p_2, \cdots, p_np1,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、付费专栏及课程。

余额充值