#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  long long int i, j, dif, t, cur, cnt, low;
  vector<long long int> v;
  vector<pair<long long int, long long int> > v1;
  bool visited[100020];
  memset(visited, false, sizeof(visited));
  for (i = 2; i <= n; i++) {
    if (!visited[i]) {
      v.push_back(i - 1);
      visited[i] = true;
      for (j = i * i; j <= n; j += i) {
        visited[j] = true;
      }
    }
  }
  vector<long long int> a(n);
  map<long long int, long long int> mp;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]] = i;
  }
  cnt = 0;
  for (i = 0; i < n; i++) {
    t = i + 1;
    dif = mp[t] - i;
    cur = mp[t];
    while (dif > 0) {
      low = lower_bound(v.begin(), v.end(), dif) - v.begin();
      if (v[low] == dif) {
        dif = 0;
        mp[a[cur]] = cur - v[low];
        mp[a[cur - v[low]]] = cur;
        swap(a[cur], a[cur - v[low]]);
        v1.push_back(make_pair(cur + 1, i + 1));
        cnt += 1;
        cur = cur - v[low];
      } else {
        dif = dif - v[low - 1];
        mp[a[cur]] = cur - v[low - 1];
        mp[a[cur - v[low - 1]]] = cur;
        swap(a[cur], a[cur - v[low - 1]]);
        v1.push_back(make_pair(cur + 1, cur - v[low - 1] + 1));
        cnt += 1;
        cur = cur - v[low - 1];
      }
    }
  }
  cout << cnt << endl;
  for (i = 0; i < cnt; i++) {
    cout << min(v1[i].first, v1[i].second) << " "
         << max(v1[i].first, v1[i].second) << endl;
  }
}
