#include <bits/stdc++.h>
using namespace std;
bool prime[1000000];
vector<int> vec;
void IsPrime() {
  prime[0] = prime[1] = 0;
  prime[2] = 1;
  for (int i = 3; i < 1000000; i++) prime[i] = i % 2 == 0 ? 0 : 1;
  int t = (int)sqrt(1000000 * 1.0);
  for (int i = 3; i <= t; i++)
    if (prime[i])
      for (int j = i * i; j < 1000000; j += 2 * i) prime[j] = 0;
  vec.clear();
  for (int i = 2; i < 110000; i++)
    if (prime[i]) vec.push_back(i);
}
int p[110000];
int a[110000];
struct listt {
  int x;
  int y;
} q;
vector<listt> ans;
void dos(int x, int y) {
  if (x == y) return;
  int l, r, mid;
  l = 0;
  r = vec.size();
  mid = (l + r) / 2;
  while (l < r) {
    if (vec[mid] > (y - x + 1))
      r = mid;
    else
      l = mid + 1;
    mid = (l + r) / 2;
  }
  mid--;
  int xx = vec[mid];
  int ip = y - xx + 1;
  swap(a[ip], a[y]);
  p[a[ip]] = ip;
  p[a[y]] = y;
  ans.push_back(listt{ip, y});
  dos(x, ip);
}
int main() {
  IsPrime();
  int i, n;
  while (~scanf("%d", &n)) {
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    for (i = 1; i <= n; i++) p[a[i]] = i;
    ans.clear();
    for (i = 1; i <= n; i++) {
      dos(i, p[i]);
    }
    cout << ans.size() << endl;
    for (i = 0; i < ans.size(); i++) {
      printf("%d %d\n", ans[i].x, ans[i].y);
    }
  }
  return 0;
}
