#include <bits/stdc++.h>
using namespace std;
int pos[100050];
int ans[100050 * 6][2];
vector<int> prime;
void init() {
  prime.resize(100050, 0);
  prime[0] = 1;
  prime[1] = 1;
  int a, b;
  for (int j = 2; j < sqrt(100050); j++) {
    if (prime[j] == 0)
      for (int k = j + j; k <= 100050; k += j) {
        prime[k] = 1;
      }
  }
}
int main() {
  int n = 0;
  init();
  while (cin >> n) {
    vector<int> arr(n);
    for (int i = 1; i <= n; i++) {
      cin >> arr[i];
      pos[arr[i]] = i;
    }
    int cont = 0;
    for (int i = 1; i <= n; i++) {
      if (arr[i] == i) continue;
      while (1) {
        for (int j = i; j < pos[i]; j++) {
          if (prime[pos[i] - j + 1] == 0) {
            ans[cont][0] = j;
            ans[cont++][1] = pos[i];
            int num = arr[j];
            swap(arr[pos[i]], arr[j]);
            swap(pos[num], pos[i]);
            break;
          }
        }
        if (arr[i] == i) break;
      }
    }
    cout << cont << endl;
    for (int i = 0; i < cont; i++) {
      cout << ans[i][0] << " " << ans[i][1] << endl;
    }
  }
  return 0;
}
