CF432C.Prime Swaps
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have an array a[1], a[2], ..., a[n], containing distinct integers from 1 to n. Your task is to sort this array in increasing order with the following operation (you may need to apply it multiple times):
- choose two indexes, i and j (1 ≤ i < j ≤ n; (j - i + 1) is a prime number);
- swap the elements on positions i and j; in other words, you are allowed to apply the following sequence of assignments: tmp = a[i], a[i] = a[j], a[j] = tmp (tmp is a temporary variable).
You do not need to minimize the number of used operations. However, you need to make sure that there are at most 5_n_ operations.
你有一个数组 a[1], a[2], …, a[n],其中包含从 1 到 n 的互不相同的整数。你的任务是通过以下操作(可多次执行)将该数组按升序排序:
- 选择两个下标 i 和 j(满足 1 ≤ i < j ≤ n,且 j − i + 1 是一个质数);
- 交换位置 i 和 j 上的元素;即允许执行如下赋值序列:tmp = a[i], a[i] = a[j], a[j] = tmp(其中 tmp 是一个临时变量)。
你无需最小化所用操作次数,但必须确保操作总数不超过 5n 次。
输入格式
The first line contains integer n (1 ≤ n ≤ 105). The next line contains n distinct integers a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ n).
第一行包含一个整数 n(1 ≤ n ≤ 105)。第二行包含 n 个互不相同的整数 a[1],a[2],…,a[n](1 ≤ a[i] ≤ n)。
输出格式
In the first line, print integer k (0 ≤ k ≤ 5_n_) — the number of used operations. Next, print the operations. Each operation must be printed as "i j" (1 ≤ i < j ≤ n; (j - i + 1) is a prime).
If there are multiple answers, you can print any of them.
第一行输出整数 k(0≤k≤5n),表示所用操作的次数。接下来输出这些操作。每个操作必须以“i j”的形式输出(其中 1≤i<j≤n,且 j−i+1 是一个质数)。
若存在多个答案,输出任意一个即可。
输入输出样例
输入#1
3 3 2 1
输出#1
1 1 3
输入#2
2 1 2
输出#2
0
输入#3
4 4 2 3 1
输出#3
3 2 4 1 2 2 4
输入解题思路,AI测评打分。不知道怎么写?