#include <bits/stdc++.h>
using namespace std;
int p[100010], a[100010], y[100010];
int main() {
  int n, t, ct = 0;
  vector<pair<int, int> > v;
  cin >> n;
  int i, j;
  for (i = 2; i <= n; i++)
    if (p[i] == 0)
      for (j = 2 * i; j <= n; j += i) p[j] = 1;
  int temp;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    y[a[i]] = i;
  }
  for (i = 1; i <= n; i++) {
    for (j = y[i]; j > i;) {
      t = i;
      while (p[j + 1 - t]) t++;
      v.push_back(make_pair(t, j));
      ct++;
      y[a[t]] = j;
      temp = a[t];
      a[t] = a[j];
      a[j] = temp;
      j = t;
    }
  }
  cout << ct << endl;
  for (i = 0; i < v.size(); i++)
    cout << v[i].first << " " << v[i].second << endl;
  return 0;
}
