#include <bits/stdc++.h>
using namespace std;
bool bad[1000001];
int primes[1000001];
int cpr = 0;
void cprime() {
  primes[cpr++] = 2;
  int i = 3;
  for (; i * i <= 100000; i += 2) {
    if (!bad[i]) {
      primes[cpr++] = i;
      for (int j = i * i; j <= 100000; j += i) bad[j] = true;
    }
  }
  for (; i <= 100000; i += 2) {
    if (!bad[i]) primes[cpr++] = i;
  }
}
int arr[1000001];
int cur[1000001];
int main() {
  ios::sync_with_stdio(false);
  cprime();
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> arr[i];
    cur[arr[i]] = i;
  }
  vector<pair<int, int> > ans;
  for (int i = 1; i <= n; ++i) {
    while (cur[i] != i) {
      int dif = cur[i] - i + 1;
      int l = 0, r = cpr - 1;
      int st = 0;
      while (l <= r) {
        int m = l + (r - l) / 2;
        if (primes[m] <= dif) {
          st = primes[m];
          l = m + 1;
        } else {
          r = m - 1;
        }
      }
      ans.push_back(make_pair(cur[i], cur[i] - st + 1));
      int f = arr[cur[i] - st + 1];
      cur[arr[cur[i] - st + 1]] = cur[i];
      cur[i] = cur[i] - st + 1;
      swap(arr[cur[i]], arr[cur[f]]);
    }
  }
  cout << ans.size() << '\n';
  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i].second << ' ' << ans[i].first << '\n';
  }
  return 0;
}
