5637: 主要掉期

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

C. 主要掉期
每次测试的时间限制
2 秒
每个测试的内存限制
256 兆字节
输入
标准输入
输出
标准输出
你有一个数组 a[1],a[2],...,a[n],包含从 1 到 n 的不同整数。您的任务是使用以下操作按递增顺序对此数组进行排序(您可能需要多次应用它):
  • 选择两个索引,i 和 j (1≤i<jn;j-i+1) 是质数);
  • 交换位置 i 和 j 上的元素;换句话说,您可以应用以下赋值序列:tmp=a[i],a[i]=a[j]a[j]=tmptmp 是一个临时变量)。
您不需要最小化已使用的操作数。但是,您需要确保最多有 5n 个操作。
输入
第一行包含整数 n (1≤n≤105)。下一行包含 n 不同的整数 a[1],a[2],...,a[n] (1≤a[i]≤n)。
输出
在第一行中,打印整数 k (0≤k≤5n - 已用操作数。接下来,打印操作。每个操作必须打印为“i j”(1≤i<j≤n;j-i+1) 是素数)。
如果有多个答案,您可以打印其中任何一个。

例子
输入
3
3 2 1
输出
1
1 3
输入
2
1 2
输出
0
输入
4
4 2 3 1
输出
3
2 4
1 2
2 4
C. Prime Swaps
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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<jn; (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 5n operations.
Input
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).
Output
In the first line, print integer k (0≤k≤5n) − the number of used operations. Next, print the operations. Each operation must be printed as "i j" (1≤i<jn; (j-i+1) is a prime).
If there are multiple answers, you can print any of them.

Examples
Input
3
3 2 1
Output
1
1 3
Input
2
1 2
Output
0
Input
4
4 2 3 1
Output
3
2 4
1 2
2 4

输入样例 复制


输出样例 复制