#include <bits/stdc++.h>
int n;
bool sito[1000010];
std::vector<int> prim;
std::vector<int>::iterator it;
void f() {
  for (int i = 2; i <= 100000; ++i)
    for (int j = 2 * i; j < 1000000; j += i) sito[j] = true;
  for (int i = 2; i <= 100000; ++i)
    if (!sito[i]) prim.push_back(i);
}
std::vector<std::pair<int, int> > r;
std::pair<int, int> temp;
int brojac;
std::map<int, int> mapa;
int a[100010];
int x, l, h;
int main() {
  f();
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &x);
    a[i] = x;
    mapa[x] = i;
  }
  for (int i = 1; i <= 100000; ++i) {
    h = mapa[i];
    l = i;
    while (h > l) {
      x = h - l + 1;
      it = std::lower_bound(prim.begin(), prim.end(), x);
      if (x == *it) {
        temp.first = l;
        temp.second = h;
        r.push_back(temp);
        std::swap(a[l], a[h]);
        std::swap(mapa[a[l]], mapa[a[h]]);
        h -= *it + 1;
      } else {
        --it;
        temp.first = h - *it + 1;
        temp.second = h;
        h -= *it - 1;
        r.push_back(temp);
        std::swap(a[temp.first], a[temp.second]);
        std::swap(mapa[a[temp.first]], mapa[a[temp.second]]);
      }
      ++brojac;
    }
  }
  printf("%d\n", brojac);
  for (int i = 0; i < brojac; ++i) printf("%d %d\n", r[i].first, r[i].second);
}
