#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
int a[MAXN];
int is[MAXN];
int p[MAXN];
int x[MAXN * 10];
int y[MAXN * 10];
bool isprime(int p) {
  if (p == 2 || p == 3)
    return 1;
  else if (p % 2 == 0 || p % 3 == 0)
    return 0;
  for (int i = 5, k = 4, j = 25; j <= p;
       i += (k = 6 - k), j += (i + i - k) << (k >> 1))
    if (!(p % i)) return 0;
  return 1;
}
void init() {
  memset(is, 0, sizeof(is));
  for (int i = 2; i <= 100010; i++) {
    if (is[i]) continue;
    for (int j = i * 2; j <= 100010; j += i) is[j] = 1;
  }
}
int main() {
  int n;
  int t;
  init();
  while (cin >> n) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      p[a[i]] = i;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      while (p[i] != i) {
        for (int j = i; j < p[i]; j++) {
          if (!is[p[i] - j + 1]) {
            x[ans] = j;
            y[ans] = p[i];
            ans++;
            t = p[i];
            p[i] = j;
            p[a[j]] = t;
            swap(a[t], a[j]);
            break;
          }
        }
      }
    }
    cout << ans << endl;
    if (ans)
      for (int i = 0; i < ans; i++) {
        printf("%d %d\n", x[i], y[i]);
      }
  }
  return 0;
}
