#include <bits/stdc++.h>
using namespace std;
int isprime(int n) {
  if (n < 2) return false;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
int p[100005], np = 0;
vector<int> get(int n) {
  vector<int> ret;
  int *lb;
  while ((lb = lower_bound(p, p + np, n)) && *lb != n)
    ret.push_back(*(lb - 1)), n = n - *(lb - 1) + 1;
  ret.push_back(n);
  return ret;
}
int main() {
  for (int i = 0; i < 100005; i++)
    if (isprime(i)) p[np++] = i;
  int n, ns[100005], arr[100005];
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    ns[arr[i]] = i;
  }
  vector<pair<int, int> > ans;
  for (int i = 1; i <= n; i++) {
    if (ns[i] == i) continue;
    vector<int> dt = get(ns[i] - i + 1);
    int ti = ns[i];
    for (int j = dt.size() - 1; j >= 0; j--) {
      int nt = ti - dt[j] + 1;
      swap(ns[arr[ti]], ns[arr[nt]]);
      swap(arr[ti], arr[nt]);
      ans.push_back(make_pair(nt, ti));
      ti = nt;
    }
  }
  cout << ans.size() << endl;
  for (auto &i : ans) cout << i.first << ' ' << i.second << endl;
  return 0;
}
