#include <bits/stdc++.h>
int a[100010];
int p[100010];
int n, ans, anx[5 * 100010], any[5 * 100010], adr[100010];
int swap(int &a, int &b) {
  int t = a;
  a = b;
  b = t;
}
int main() {
  int i, j;
  int now, t;
  scanf("%d", &n);
  for (i = 2; i <= n; ++i)
    if (!p[i])
      for (j = 2 * i; j <= n; j += i) p[j] = 1;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    adr[a[i]] = i;
  }
  ans = 0;
  for (i = 1; i <= n; i++)
    for (now = adr[i]; now > i;) {
      t = i;
      while (p[now - t + 1]) t++;
      anx[++ans] = t;
      any[ans] = now;
      adr[a[t]] = now;
      swap(a[t], a[now]);
      now = t;
    }
  printf("%d\n", ans);
  for (i = 1; i <= ans; i++) printf("%d %d\n", anx[i], any[i]);
}
