Description
You have an arrayA[1], bytesA[2], middle..., middleA[N], Containing distinct integers from 1N. 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,IAndJ(1 digit ≤ DigitILatency <latencyJLimit ≤ limitN;(JAccept-Encoding-ISecond + second 1) is a prime number );
- Swap the elements on positionsIAndJ; In other words, you are allowed to apply the following sequence of assignments:TMPSignature = SignatureA[I], RoleA[I] Bytes = bytesA[J], RoleA[J] Bytes = bytesTMP(TMPIs 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 5NOperations.
Input
The first line contains integerN(1 digit ≤ DigitNLimit ≤ limit 105). The next line containsNDistinct integersA[1], bytesA[2], middle..., middleA[N] (1 limit ≤ limitA[I] Limit ≤ limitN).
Output
In the first line, print integerK(0 bytes ≤ bytesKLimit ≤ limit 5N)-The number of used operations. Next, print the operations. each operation must be printed"IJ"(1 digit ≤ DigitILatency <latencyJLimit ≤ limitN;(JAccept-Encoding-IMemory + Memory 1) is a prime ).
If there are multiple answers, you can print any of them.
Sample Input
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
The sequence with N numbers is ordered by exchange. The principle of exchange is that the number AI and AJ of each exchange (J-I + 1) must be a prime number, it must be completed in step 5.
Idea: it is easy to consider the gedebach conjecture. Although this conjecture has not been proved, scientists have not yet found a counterexample, which is applicable when the data Scope of this question is limited. It can be obtained by conjecture that each number greater than or equal to 5 can be obtained by adding three prime numbers, while 2 and 3 are prime numbers, 4 = 2 + 2, therefore, all numbers greater than or equal to 2 can be expressed by prime numbers. Therefore, regardless of the number of I and J, I and J can be exchanged in three steps. It is known that an unordered series must be exchanged for up to n-1 times to become an ordered series. Therefore, the answer is less than or equal to 3 (n-1) and less than or equal to 5N.
/** Author: Joshua * created time: October 16, Sunday, July 20, 2014 * file name: C. CPP */# include <cstdio> # include <cstring> # include <algorithm> using namespace STD; # define maxn 100005 int A [maxn], L [maxn <2], R [maxn <2]; bool f [maxn]; int N, ans; void primenumber () {memset (F, true, sizeof (f )); f [0] = f [1] = false; For (INT I = 2; I <maxn; ++ I) if (F [I]) for (Int J = I + I; j <maxn; j + = I) f [J] = false;} void change (INT X, int y) {If (x = Y) return; If (x> Y) Swap (x, y); For (INT I = y; I> X; I --) if (F [I-x + 1]) {swap (A [I], a [x]); L [++ ANS] = X; R [ANS] = I; change (I, Y); break ;}} void solve () {ans = 0; For (INT I = 1; I <= N; ++ I) scanf ("% d", & A [I]); For (INT I = 1; I <= N; ++ I) while (A [I]! = I) Change (I, a [I]); printf ("% d \ n", ANS); For (INT I = 1; I <= ans; ++ I) printf ("% d \ n", l [I], R [I]);} int main () {primenumber (); while (scanf ("% d", & n) = 1) solve (); Return 0 ;}