#include <bits/stdc++.h>
using namespace std;
using namespace std;
vector<bool> isp(1000000 + 5, false);
vector<int> p, val(1000000 + 1), vis(100000 + 7);
vector<pair<int, int> > ans;
void sieveo() {
  isp[0] = isp[1] = true;
  for (int i = 2; i <= sqrt(1000000); i++)
    if (!isp[i])
      for (int j = 2; i * j <= 1000000; j++) isp[i * j] = true;
  for (int i = 0; i <= 1000000; i++)
    if (!isp[i]) p.push_back(i);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  sieveo();
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> val[i];
    vis[val[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (val[i] != i) {
      int x = vis[i];
      for (int j = vis[i] - i + 1; j > 1; j--)
        if (!isp[j]) {
          swap(val[x], val[x - j + 1]);
          ans.push_back(make_pair(x - j + 1, x));
          vis[val[x]] = x;
          vis[val[x - j + 1]] = x - j + 1;
          i--;
          break;
        }
    }
  }
  cout << ans.size() << '\n';
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << '\n';
}
