CF432C.Prime Swaps

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have an array a[1],a[2],...,a[n]a[1],a[2],...,a[n] , containing distinct integers from 11 to nn . 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, ii and jj ( 1<=i<j<=n ; (ji+1)(j-i+1) is a prime number);
  • swap the elements on positions ii and jj ; in other words, you are allowed to apply the following sequence of assignments: tmp=a[i],a[i]=a[j],a[j]=tmptmp=a[i],a[i]=a[j],a[j]=tmp ( tmptmp 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 5n5n operations.

输入格式

The first line contains integer nn (1<=n<=105)(1<=n<=10^{5}) . The next line contains nn distinct integers a[1],a[2],...,a[n]a[1],a[2],...,a[n] (1<=a[i]<=n)(1<=a[i]<=n) .

输出格式

In the first line, print integer kk (0<=k<=5n)(0<=k<=5n) — the number of used operations. Next, print the operations. Each operation must be printed as " ii jj " ( 1<=i<j<=n ; (ji+1)(j-i+1) is a prime).

If there are multiple answers, you can print any of them.

输入输出样例

  • 输入#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
    
首页