#include <bits/stdc++.h>
using namespace std;
int const MAX = 1e5 + 5;
int a[MAX], x[5 * MAX], y[5 * MAX], pos[MAX];
bool prime[MAX];
void get_prime() {
  memset(prime, true, sizeof(prime));
  prime[1] = false;
  for (int i = 2; i <= sqrt(MAX); i++)
    if (prime[i])
      for (int j = i * i; j <= MAX; j += i) prime[j] = false;
}
int main() {
  int n;
  scanf("%d", &n);
  get_prime();
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pos[a[i]] = i;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    for (int now = pos[i]; now > i;) {
      int tmp = i;
      while (!prime[now - tmp + 1]) tmp++;
      x[cnt] = tmp;
      y[cnt++] = now;
      pos[a[tmp]] = now;
      swap(a[tmp], a[now]);
      now = tmp;
    }
  }
  printf("%d\n", cnt);
  for (int i = 0; i < cnt; i++) printf("%d %d\n", x[i], y[i]);
}
