#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, a[maxn], vt[maxn], sl, p[maxn], is_p[maxn];
vector<pair<int, int> > kq;
bool cmp(int i, int j) { return a[i] < a[j]; }
void doi(int x, int y) {
  swap(vt[a[x]], vt[a[y]]);
  swap(a[x], a[y]);
  kq.push_back(make_pair(y + 1, x + 1));
}
int main() {
  for (int i = 2; i <= 100000; i++) is_p[i] = 1;
  for (int i = 2; i <= 100000; i++)
    if (is_p[i])
      for (long long j = i; i * j <= 100000; j++) is_p[i * j] = 0;
  for (int i = 1; i <= 100000; i++)
    if (is_p[i]) p[sl++] = i;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) vt[i] = i;
  int dem = 0;
  sort(vt, vt + n, cmp);
  for (int i = 0; i < n; i++) a[vt[i]] = i;
  for (int i = 0; i < n; i++) {
    while (vt[i] != i) {
      int v = p[upper_bound(p, p + sl, vt[i] - i + 1) - p - 1];
      doi(vt[i], vt[i] + 1 - v);
    }
  }
  cout << kq.size() << endl;
  for (int i = 0; i < kq.size(); i++)
    printf("%d %d\n", kq[i].first, kq[i].second);
  fclose(stdout);
}
