#include <bits/stdc++.h>
using namespace std;
bool comp[100010];
int P[100010];
int seive(int n, int* P) {
  int p, q, K = 0;
  comp[1] = true;
  char even = 1;
  for (p = 2; p * p <= n; p += 2) {
    if (!comp[p]) {
      for (q = p * p; q <= n; q += p * (2 - even)) comp[q] = true;
    }
    if (p == 2) --p, even = 0;
  }
  for (int i = (1); i <= (n); ++i)
    if (!comp[i]) P[K++] = i;
  return K;
}
int match[100010];
int main() {
  int N;
  cin >> N;
  vector<int> muls;
  int K = seive(N, P);
  int ans = 0;
  for (int i = (K - 1); i >= (0); --i) {
    muls.clear();
    muls.reserve((N + P[i] - 1) / P[i]);
    for (int v = 1, p = P[i]; p <= N; v++, p += P[i]) {
      if (!match[p]) muls.push_back(p);
    }
    assert(muls.size() >= 1);
    if (muls.size() == 1) continue;
    int M = muls.size();
    swap(muls[1], muls[M - 1]);
    int a, b;
    for (int j = 0; j < M - 1; j += 2) {
      a = muls[j], b = muls[j + 1];
      assert(a != b && 1 <= a && a <= N && 1 <= b && b <= N && !match[a] &&
             !match[b]);
      match[a] = b;
      match[b] = a;
      ans++;
    }
  }
  cout << ans << endl;
  for (int i = (1); i <= (N); ++i) {
    if (match[i] > i) printf("%d %d\n", i, match[i]);
  }
}
