#include <bits/stdc++.h>
using namespace std;
int pos[100050];
int a[100050];
int ans[100050 * 6][2];
int Is_or[100050];
void init() {
  memset(Is_or, 0, sizeof(Is_or));
  Is_or[0] = 1;
  Is_or[1] = 1;
  int a, b;
  for (int j = 2; j < sqrt(100050); j++) {
    if (Is_or[j] == 0)
      for (int k = j + j; k <= 100050; k += j) {
        Is_or[k] = 1;
      }
  }
}
int main() {
  int n;
  init();
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      pos[a[i]] = i;
    }
    int cont = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] == i) continue;
      while (1) {
        for (int j = i; j < pos[i]; j++) {
          if (Is_or[pos[i] - j + 1] == 0) {
            ans[cont][0] = j;
            ans[cont++][1] = pos[i];
            int num = a[j];
            swap(a[pos[i]], a[j]);
            swap(pos[num], pos[i]);
            break;
          }
        }
        if (a[i] == i) break;
      }
    }
    printf("%d\n", cont);
    for (int i = 0; i < cont; i++) {
      printf("%d %d\n", ans[i][0], ans[i][1]);
    }
  }
}
