#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 100 + 5;
int n, a[maxn], t[maxn];
vector<int> v;
bool chek[maxn];
vector<pair<int, int> > w;
void first() {
  for (int i = 2; i * i <= n; i++)
    if (chek[i] == false)
      for (int j = i * i; j <= n; j += i) chek[j] = true;
  for (int i = 2; i <= n; i++)
    if (chek[i] == false) v.push_back(i);
}
int binery(int x) {
  int second = 0, e = v.size(), mid, javab = 2;
  while (second < e) {
    mid = (second + e) / 2;
    if (v[mid] <= x) {
      javab = v[mid];
      second = mid + 1;
    } else
      e = mid;
  }
  return javab;
}
int main() {
  ios::sync_with_stdio(false);
  int x;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
    t[a[i]] = i;
  }
  first();
  for (int i = 0; i < n; i++)
    while (t[i] > i) {
      x = binery(t[i] - i + 1);
      x = t[i] - x + 1;
      w.push_back(make_pair(x, t[i]));
      swap(a[t[i]], a[x]);
      swap(t[a[x]], t[a[t[i]]]);
    }
  cout << (int)w.size() << endl;
  for (int i = 0; i < (int)w.size(); i++)
    cout << w[i].first + 1 << " " << w[i].second + 1 << endl;
  return 0;
}
