public static void main(String... args) throws IOException {
        MyScanner sc = new MyScanner();
        int PL = 500011;
        boolean[] p = new boolean[PL];

        for (int i = 0; i < PL; i++) {
            p[i] = true;
        }
        for (int i = 2; i < PL; i++) {
            for (int j = 2 * i; j < PL; j += i) {
                p[j] = false;
            }
        }

        int n = sc.nextInt();
        Pair[] v = new Pair[n];
        Pair[] sv = new Pair[n];
        
        for (int i = 0; i < n; i++) {
            v[i] = new Pair(sc.nextInt(), i);
            sv[i] = v[i];
        }
        
        Arrays.sort(sv, (a, b) -> (a.v == b.v)? a.ind - b.ind : a.v - b.v);
        StringBuilder sb = new StringBuilder();
        int count = 0;
        
        for (int i = 0; i < n; i++) {
            Pair l = sv[i];
            while (l.ind != i){
                int range = l.ind - i + 1;
                while (!p[range]){
                    range--;
                }
                int oldInd = l.ind;
                int newInd = l.ind - range + 1;
                
                Pair tmp = v[newInd];
                v[newInd] = l;
                v[oldInd] = tmp;
                
                v[oldInd].ind = oldInd;
                v[newInd].ind = newInd;
                
                sb.append(newInd+1).append(' ').append(oldInd+1).append('\n');
                count++;
            }
        }
        
        System.out.println(count);
        System.out.println(sb.toString());
    }