#include <bits/stdc++.h>
using namespace std;
bool com[100001];
int n;
vector<int> vec;
vector<pair<int, int> > out;
void sieve() {
  com[0] = com[1] = 1;
  for (int i = 2; i * i <= 1e5; i++) {
    if (!com[i]) {
      for (int j = i * i; j <= 1e5; j += i) com[j] = 1;
    }
  }
}
void f(int i, int j) {
  if (i == j) return;
  if (i > j) swap(i, j);
  for (int x = j; x > i; x--) {
    if (!com[x - i + 1]) {
      swap(vec[i], vec[x]);
      out.push_back(make_pair(i, x));
      f(x, j);
      return;
    }
  }
}
int main() {
  sieve();
  while (cin >> n) {
    vec.resize(n + 1);
    for (int i = 1; i <= n; i++) cin >> vec[i];
    for (int i = 1; i <= n; i++) {
      while (vec[i] != i) f(i, vec[i]);
    }
    cout << out.size() << endl;
    for (int i = 0; i < out.size(); i++)
      cout << out[i].first << " " << out[i].second << endl;
  }
}
