/** Micro Mezz Macro Flation -- Overheated Economy ., Last Update: Jun. 15th 2014 **/ //{

/** Header .. **/ //{
#pragma comment(linker, "/STACK:36777216")
//#pragma GCC optimize ("O2")
#define LOCAL
//#include "testlib.h"
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <climits>
#include <cassert>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>

//#include <tr1/unordered_set>
//#include <tr1/unordered_map>
//#include <array>

using namespace std;

#define REP(i, n) for (int i=0;i<n;++i)
#define FOR(i, a, b) for (int i=a;i<b;++i)
#define DWN(i, b, a) for (int i=b-1;i>=a;--i)
#define REP_1(i, n) for (int i=1;i<=n;++i)
#define FOR_1(i, a, b) for (int i=a;i<=b;++i)
#define DWN_1(i, b, a) for (int i=b;i>=a;--i)
#define REP_C(i, n) for (int n____=n,i=0;i<n____;++i)
#define FOR_C(i, a, b) for (int b____=b,i=a;i<b____;++i)
#define DWN_C(i, b, a) for (int a____=a,i=b-1;i>=a____;--i)
#define REP_N(i, n) for (i=0;i<n;++i)
#define FOR_N(i, a, b) for (i=a;i<b;++i)
#define DWN_N(i, b, a) for (i=b-1;i>=a;--i)
#define REP_1_C(i, n) for (int n____=n,i=1;i<=n____;++i)
#define FOR_1_C(i, a, b) for (int b____=b,i=a;i<=b____;++i)
#define DWN_1_C(i, b, a) for (int a____=a,i=b;i>=a____;--i)
#define REP_1_N(i, n) for (i=1;i<=n;++i)
#define FOR_1_N(i, a, b) for (i=a;i<=b;++i)
#define DWN_1_N(i, b, a) for (i=b;i>=a;--i)
#define REP_C_N(i, n) for (int n____=(i=0,n);i<n____;++i)
#define FOR_C_N(i, a, b) for (int b____=(i=0,b);i<b____;++i)
#define DWN_C_N(i, b, a) for (int a____=(i=b-1,a);i>=a____;--i)
#define REP_1_C_N(i, n) for (int n____=(i=1,n);i<=n____;++i)
#define FOR_1_C_N(i, a, b) for (int b____=(i=a,b);i<=b____;++i)
#define DWN_1_C_N(i, b, a) for (int a____=(i=b,a);i>=a____;--i)

#define ECH(it, A) for (__typeof(A.begin()) it=A.begin(); it != A.end(); ++it)
#define REP_S(i, str) for (char*i=str;*i;++i)
#define REP_L(i, hd, suc) for (int i=hd;i;i=suc[i])
#define REP_G(i, u) REP_L(i,hd[u],suc)
#define REP_SS(x, s) for (int x=s;x;x=(x-1)&s)
#define DO(n) for ( int ____n = n; ____n-->0; )
#define REP_2(i, j, n, m) REP(i, n) REP(j, m)
#define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m)
#define REP_3(i, j, k, n, m, l) REP(i, n) REP(j, m) REP(k, l)
#define REP_3_1(i, j, k, n, m, l) REP_1(i, n) REP_1(j, m) REP_1(k, l)
#define REP_4(i, j, k, ii, n, m, l, nn) REP(i, n) REP(j, m) REP(k, l) REP(ii, nn)
#define REP_4_1(i, j, k, ii, n, m, l, nn) REP_1(i, n) REP_1(j, m) REP_1(k, l) REP_1(ii, nn)

#define ALL(A) A.begin(), A.end()
#define LLA(A) A.rbegin(), A.rend()
#define CPY(A, B) memcpy(A, B, sizeof(A))
#define INS(A, P, B) A.insert(A.begin() + P, B)
#define ERS(A, P) A.erase(A.begin() + P)
#define LBD(A, x) (lower_bound(ALL(A), x) - A.begin())
#define UBD(A, x) (lower_bound(ALL(A), x) - A.begin())
#define CTN(T, x) (T.find(x) != T.end())
#define SZ(A) int((A).size())
#define PB push_back
#define MP(A, B) make_pair(A, B)
#define PTT pair<T, T>
#define Ts *this
#define rTs return Ts
#define fi first
#define se second
#define re real()
#define im imag()

#define Rush for(int ____T=RD(); ____T--;)
#define Display(A, n, m) {                      \
  REP(i, n){		                            \
        REP(j, m-1) cout << A[i][j] << " ";     \
        cout << A[i][m-1] << endl;		        \
	}						                    \
}
#define Display_1(A, n, m) {                    \
	REP_1(i, n){		                        \
        REP_1(j, m-1) cout << A[i][j] << " ";   \
        cout << A[i][m] << endl;		        \
	}						                    \
}

typedef long long LL;
//typedef long double DB;
typedef double DB;
typedef unsigned uint;
typedef unsigned long long uLL;

typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<LL> VL;
typedef vector<DB> VF;
typedef set<int> SI;
typedef set<string> SS;
typedef map<int, int> MII;
typedef map<string, int> MSI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<VII> VVII;

template<class T> inline T& RD(T &);
template<class T> inline void OT(const T &);
//inline int RD(){int x; return RD(x);}
inline LL RD(){LL x; return RD(x);}
inline DB& RF(DB &);
inline DB RF(){DB x; return RF(x);}
inline char* RS(char *s);
inline char& RC(char &c);
inline char RC();
inline char& RC(char &c){scanf(" %c", &c); return c;}
inline char RC(){char c; return RC(c);}
//inline char& RC(char &c){c = getchar(); return c;}
//inline char RC(){return getchar();}

template<class T> inline T& RDD(T &);
inline LL RDD(){LL x; return RDD(x);}

template<class T0, class T1> inline T0& RD(T0 &x0, T1 &x1){RD(x0), RD(x1); return x0;}
template<class T0, class T1, class T2> inline T0& RD(T0 &x0, T1 &x1, T2 &x2){RD(x0), RD(x1), RD(x2); return x0;}
template<class T0, class T1, class T2, class T3> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3){RD(x0), RD(x1), RD(x2), RD(x3); return x0;}
template<class T0, class T1, class T2, class T3, class T4> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4); return x0;}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5); return x0;}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6); return x0;}
template<class T0, class T1> inline void OT(const T0 &x0, const T1 &x1){OT(x0), OT(x1);}
template<class T0, class T1, class T2> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2){OT(x0), OT(x1), OT(x2);}
template<class T0, class T1, class T2, class T3> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3){OT(x0), OT(x1), OT(x2), OT(x3);}
template<class T0, class T1, class T2, class T3, class T4> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5, const T6 &x6){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);}
inline char& RC(char &a, char &b){RC(a), RC(b); return a;}
inline char& RC(char &a, char &b, char &c){RC(a), RC(b), RC(c); return a;}
inline char& RC(char &a, char &b, char &c, char &d){RC(a), RC(b), RC(c), RC(d); return a;}
inline char& RC(char &a, char &b, char &c, char &d, char &e){RC(a), RC(b), RC(c), RC(d), RC(e); return a;}
inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f); return a;}
inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f, char &g){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f), RC(g); return a;}
inline DB& RF(DB &a, DB &b){RF(a), RF(b); return a;}
inline DB& RF(DB &a, DB &b, DB &c){RF(a), RF(b), RF(c); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d){RF(a), RF(b), RF(c), RF(d); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e){RF(a), RF(b), RF(c), RF(d), RF(e); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f, DB &g){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g); return a;}
inline void RS(char *s1, char *s2){RS(s1), RS(s2);}
inline void RS(char *s1, char *s2, char *s3){RS(s1), RS(s2), RS(s3);}
template<class T0,class T1>inline void RDD(T0&a, T1&b){RDD(a),RDD(b);}
template<class T0,class T1,class T2>inline void RDD(T0&a, T1&b, T2&c){RDD(a),RDD(b),RDD(c);}

template<class T> inline void RST(T &A){memset(A, 0, sizeof(A));}
template<class T> inline void FLC(T &A, int x){memset(A, x, sizeof(A));}
template<class T> inline void CLR(T &A){A.clear();}

template<class T0, class T1> inline void RST(T0 &A0, T1 &A1){RST(A0), RST(A1);}
template<class T0, class T1, class T2> inline void RST(T0 &A0, T1 &A1, T2 &A2){RST(A0), RST(A1), RST(A2);}
template<class T0, class T1, class T2, class T3> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3){RST(A0), RST(A1), RST(A2), RST(A3);}
template<class T0, class T1, class T2, class T3, class T4> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);}
template<class T0, class T1> inline void FLC(T0 &A0, T1 &A1, int x){FLC(A0, x), FLC(A1, x);}
template<class T0, class T1, class T2> inline void FLC(T0 &A0, T1 &A1, T2 &A2, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x);}
template<class T0, class T1, class T2, class T3> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x);}
template<class T0, class T1, class T2, class T3, class T4> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x), FLC(A6, x);}
template<class T> inline void CLR(priority_queue<T, vector<T>, less<T> > &Q){while (!Q.empty()) Q.pop();}
template<class T> inline void CLR(priority_queue<T, vector<T>, greater<T> > &Q){while (!Q.empty()) Q.pop();}
template<class T> inline void CLR(stack<T> &S){while (!S.empty()) S.pop();}
template<class T> inline void CLR(queue<T> &Q){while (!Q.empty()) Q.pop();}

template<class T0, class T1> inline void CLR(T0 &A0, T1 &A1){CLR(A0), CLR(A1);}
template<class T0, class T1, class T2> inline void CLR(T0 &A0, T1 &A1, T2 &A2){CLR(A0), CLR(A1), CLR(A2);}
template<class T0, class T1, class T2, class T3> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3){CLR(A0), CLR(A1), CLR(A2), CLR(A3);}
template<class T0, class T1, class T2, class T3, class T4> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6);}
template<class T> inline void CLR(T &A, int n){REP(i, n) CLR(A[i]);}

template<class T> inline bool EPT(T &a){return a.empty();}
template<class T> inline T& SRT(T &A){sort(ALL(A)); return A;}
template<class T, class C> inline T& SRT(T &A, C B){sort(ALL(A), B); return A;}
template<class T> inline T& RVS(T &A){reverse(ALL(A)); return A;}
template<class T> inline T& UNQQ(T &A){A.resize(unique(ALL(A))-A.begin());return A;}
template<class T> inline T& UNQ(T &A){SRT(A);return UNQQ(A);}

//}

/** Constant List .. **/ //{

const int MOD = int(1e9) + 7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const DB EPS = 1e-9;
const DB OO = 1e20;
const DB PI = acos(-1.0); //M_PI;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};

//}

/** Add On .. **/ //{
// <<= '0. Nichi Joo ., //{

template<class T> inline T& checkMin(T &a,const T b){if (b<a) a=b;return a;}
template<class T> inline T& checkMax(T &a,const T b){if (a<b) a=b;return a;}
template<class T> inline T& checkMin(T &a, T &b, const T x){checkMin(a, x), checkMin(b, x);return a;}
template<class T> inline T& checkMax(T &a, T &b, const T x){checkMax(a, x), checkMax(b, x);return a;}
template <class T, class C> inline T& checkMin(T& a, const T b, C c){if (c(b,a)) a = b;return a;}
template <class T, class C> inline T& checkMax(T& a, const T b, C c){if (c(a,b)) a = b;return a;}
template<class T> inline T min(T a, T b, T c){return min(min(a, b), c);}
template<class T> inline T max(T a, T b, T c){return max(max(a, b), c);}
template<class T> inline T min(T a, T b, T c, T d){return min(min(a, b), min(c, d));}
template<class T> inline T max(T a, T b, T c, T d){return max(max(a, b), max(c, d));}
template<class T> inline T min(T a, T b, T c, T d, T e){return min(min(min(a,b),min(c,d)),e);}
template<class T> inline T max(T a, T b, T c, T d, T e){return max(max(max(a,b),max(c,d)),e);}
template<class T> inline T sqr(T a){return a*a;}
template<class T> inline T cub(T a){return a*a*a;}
template<class T> inline T ceil(T x, T y){return (x - 1) / y + 1;}
template<class T> T abs(T x){return x>0?x:-x;}
inline int sgn(DB x){return x < -EPS ? -1 : x > EPS;}
inline int sgn(DB x, DB y){return sgn(x - y);}

inline DB cos(DB a, DB b, DB c){return (sqr(a)+sqr(b)-sqr(c))/(2*a*b);}
inline DB cot(DB x){return 1./tan(x);};
inline DB sec(DB x){return 1./cos(x);};
inline DB csc(DB x){return 1./sin(x);};

//}
// <<= '1. Bitwise Operation ., //{
namespace BO{

inline bool _1(int x, int i){return bool(x&1<<i);}
inline bool _1(LL x, int i){return bool(x&1LL<<i);}
inline LL _1(int i){return 1LL<<i;}
inline LL _U(int i){return _1(i) - 1;};

inline int reverse_bits(int x){
    x = ((x >> 1) & 0x55555555) | ((x << 1) & 0xaaaaaaaa);
    x = ((x >> 2) & 0x33333333) | ((x << 2) & 0xcccccccc);
    x = ((x >> 4) & 0x0f0f0f0f) | ((x << 4) & 0xf0f0f0f0);
    x = ((x >> 8) & 0x00ff00ff) | ((x << 8) & 0xff00ff00);
    x = ((x >>16) & 0x0000ffff) | ((x <<16) & 0xffff0000);
    return x;
}

inline LL reverse_bits(LL x){
    x = ((x >> 1) & 0x5555555555555555LL) | ((x << 1) & 0xaaaaaaaaaaaaaaaaLL);
    x = ((x >> 2) & 0x3333333333333333LL) | ((x << 2) & 0xccccccccccccccccLL);
    x = ((x >> 4) & 0x0f0f0f0f0f0f0f0fLL) | ((x << 4) & 0xf0f0f0f0f0f0f0f0LL);
    x = ((x >> 8) & 0x00ff00ff00ff00ffLL) | ((x << 8) & 0xff00ff00ff00ff00LL);
    x = ((x >>16) & 0x0000ffff0000ffffLL) | ((x <<16) & 0xffff0000ffff0000LL);
    x = ((x >>32) & 0x00000000ffffffffLL) | ((x <<32) & 0xffffffff00000000LL);
    return x;
}

template<class T> inline bool odd(T x){return x&1;}
template<class T> inline bool even(T x){return !odd(x);}
template<class T> inline T low_bit(T x) {return x & -x;}
template<class T> inline T high_bit(T x) {T p = low_bit(x);while (p != x) x -= p, p = low_bit(x);return p;}
template<class T> inline T cover_bit(T x){T p = 1; while (p < x) p <<= 1;return p;}
template<class T> inline int cover_idx(T x){int p = 0; while (_1(p) < x ) ++p; return p;}

inline int clz(int x){return __builtin_clz(x);}
inline int clz(LL x){return __builtin_clzll(x);}
inline int ctz(int x){return __builtin_ctz(x);}
inline int ctz(LL x){return __builtin_ctzll(x);}
inline int lg2(int x){return !x ? -1 : 31 - clz(x);}
inline int lg2(LL x){return !x ? -1 : 63 - clz(x);}
inline int low_idx(int x){return !x ? -1 : ctz(x);}
inline int low_idx(LL x){return !x ? -1 : ctz(x);}
inline int high_idx(int x){return lg2(x);}
inline int high_idx(LL x){return lg2(x);}
inline int parity(int x){return __builtin_parity(x);}
inline int parity(LL x){return __builtin_parityll(x);}
inline int count_bits(int x){return __builtin_popcount(x);}
inline int count_bits(LL x){return __builtin_popcountll(x);}

} using namespace BO;//}

// <<= '9. Comutational Geometry .,//{
namespace CG{

#define cPo const Po&
#define cLine const Line&
#define cSeg const Seg&

inline DB dist2(DB x,DB y){return sqr(x)+sqr(y);}

struct Po{
    DB x,y; Po(DB x=0,DB y=0):x(x),y(y){}

    void in(){RF(x,y);}void out(){printf("(%.2f,%.2f)",x,y);}
    inline friend istream&operator>>(istream&i,Po&p){return i>>p.x>>p.y;}
    inline friend ostream&operator<<(ostream&o,Po p){return o<<"("<<p.x<<", "<<p.y<< ")";}

    Po operator-()const{return Po(-x,-y);}
    Po&operator+=(cPo p){x+=p.x,y+=p.y;rTs;}Po&operator-=(cPo p){x-=p.x,y-=p.y;rTs;}
    Po&operator*=(DB k){x*=k,y*=k;rTs;}Po&operator/=(DB k){x/=k,y/=k;rTs;}
    Po&operator*=(cPo p){rTs=Ts*p;}Po&operator/=(cPo p){rTs=Ts/p;}
    Po operator+(cPo p)const{return Po(x+p.x,y+p.y);}Po operator-(cPo p)const{return Po(x-p.x,y-p.y);}
    Po operator*(DB k)const{return Po(x*k,y*k);}Po operator/(DB k)const{return Po(x/k,y/k);}
    Po operator*(cPo p)const{return Po(x*p.x-y*p.y,y*p.x+x*p.y);}Po operator/(cPo p)const{return Po(x*p.x+y*p.y,y*p.x-x*p.y)/p.len2();}

    bool operator==(cPo p)const{return!sgn(x,p.x)&&!sgn(y,p.y);};bool operator!=(cPo p)const{return sgn(x,p.x)||sgn(y,p.y);}
    bool operator<(cPo p)const{return sgn(x,p.x)<0||!sgn(x,p.x)&&sgn(y,p.y)<0;}bool operator<=(cPo p)const{return sgn(x,p.x)<0||!sgn(x,p.x)&&sgn(y,p.y)<=0;}
    bool operator>(cPo p)const{return!(Ts<=p);}bool operator >=(cPo p)const{return!(Ts<p);}

    DB len2()const{return dist2(x,y);}DB len()const{return sqrt(len2());}DB arg()const{return atan2(y,x);}
    Po&_1(){rTs/=len();}Po&conj(){y=-y;rTs;}Po&lt(){swap(x,y),x=-x;rTs;}Po&rt(){swap(x,y),y=-y;rTs;}
    Po&rot(DB a,cPo o=Po()){Ts-=o;Ts*=Po(cos(a),sin(a));rTs+=o;}
};

inline DB dot(DB x1,DB y1,DB x2,DB y2){return x1*x2+y1*y2;}
inline DB dot(cPo a,cPo b){return dot(a.x,a.y,b.x,b.y);}
inline DB dot(cPo p0,cPo p1,cPo p2){return dot(p1-p0,p2-p0);}
inline DB det(DB x1,DB y1,DB x2,DB y2){return x1*y2-x2*y1;}
inline DB det(cPo a,cPo b){return det(a.x,a.y,b.x,b.y);}
inline DB det(cPo p0,cPo p1,cPo p2){return det(p1-p0,p2-p0);}
inline DB ang(cPo p0,cPo p1){return acos(dot(p0,p1)/p0.len()/p1.len());}
inline DB ang(cPo p0,cPo p1,cPo p2){return ang(p1-p0,p2-p0);}
inline DB ang(cPo p0,cPo p1,cPo p2,cPo p3){return ang(p1-p0,p3-p2);}
inline DB dist2(const Po &a, const Po &b){return dist2(a.x-b.x, a.y-b.y);}
template<class T1, class T2> inline int dett(const T1 &x, const T2 &y){return sgn(det(x, y));}
template<class T1, class T2, class T3> inline int dett(const T1 &x, const T2 &y, const T3 &z){return sgn(det(x, y, z));}
template<class T1, class T2, class T3, class T4> inline int dett(const T1 &x, const T2 &y, const T3 &z, const T4 &w){return sgn(det(x, y, z, w));}
template<class T1, class T2> inline int dott(const T1 &x, const T2 &y){return sgn(dot(x, y));}
template<class T1, class T2, class T3> inline int dott(const T1 &x, const T2 &y, const T3 &z){return sgn(dot(x, y, z));}
template<class T1, class T2, class T3, class T4> inline int dott(const T1 &x, const T2 &y, const T3 &z, const T4 &w){return sgn(dot(x, y, z, w));}
template<class T1, class T2> inline DB arg(const T1 &x, const T2 &y){DB a=ang(x,y);return~dett(x,y)?a:2*PI-a;}
template<class T1, class T2, class T3> inline DB arg(const T1 &x, const T2 &y, const T3 &z){DB a=ang(x,y,z);return~dett(x,y,z)?a:2*PI-a;}
template<class T1, class T2, class T3, class T4> inline DB arg(const T1 &x, const T2 &y, const T3 &z, const T4 &w){DB a=ang(x,y,z,w);return~dett(x,y,z,w)?a:2*PI-a;}
template<class T1, class T2> inline DB dist(const T1 &x, const T2 &y){return sqrt(dist2(x, y));}
template<class T1, class T2, class T3> inline DB dist(const T1 &x, const T2 &y, const T3 &z){return sqrt(dist2(x, y, z));}
inline Po _1(Po p){return p._1();}inline Po conj(Po p){return p.conj();}
inline Po lt(Po p){return p.lt();}inline Po rt(Po p){return p.rt();}
inline Po rot(Po p,DB a,cPo o=Po()){return p.rot(a,o);}
inline Po operator *(DB k,cPo p){return p*k;}
inline Po operator /(DB k,cPo p){return conj(p)*k/p.len2();}

typedef vector<Po> VP;

struct Line{
    Po a,b;Line(cPo a=Po(),cPo b=Po()):a(a),b(b){}
    Line(DB x0,DB y0,DB x1,DB y1):a(Po(x0,y0)),b(Po(x1,y1)){}
    Line(cLine l):a(l.a),b(l.b){}

    //Ax+By+C=0
    Line(DB A,DB B,DB C){
        C=-C;if(!::sgn(A))a=Po(0,C/B),b=Po(1,C/B);
        else if(!::sgn(B))a=Po(C/A,0),b=Po(C/A,1);
        else a=Po(0,C/B),b=Po(1,(C-A)/B);
    }

    void in(){a.in(),b.in();}
    inline friend istream&operator>>(istream&i,Line& p){return i>>p.a>>p.b;}
    inline friend ostream&operator<<(ostream&o,Line p){return o<<p.a<<"-"<< p.b;}

    bool operator<(cLine p)const{
        return a<p.a||a==p.a&&b<p.b;
    }

    Line operator+(cPo x)const{return Line(a+x,b+x);}
    Line operator-(cPo x)const{return Line(a-x,b-x);}
    Line operator*(DB k)const{return Line(a*k,b*k);}
    Line operator/(DB k)const{return Line(a/k,b/k);}

    Po operator*(cLine)const;
    Po d()const{return b-a;}DB len2()const{return d().len2();}DB len()const{return d().len();}DB arg()const{return d().arg();}

    int sgn(cPo p)const{return dett(a, b, p);}
    int sgn(cLine)const;

    bool sameSgn(cPo  p1,cPo  p2)const{return sgn(p1)==sgn(p2);}
    void getEquation(DB&K,DB&B)const{
        K = ::sgn(a.x, b.x) ? (b.y-a.y)/(b.x-a.x) : OO;
        B = a.y - K*a.x;
    }
    void getEquation(DB&A,DB&B,DB&C)const{A=a.y-b.y,B=b.x-a.x,C=det(a, b);}

    Line&push(DB r){ // 正数右手螺旋向里
        Po v=d()._1().lt()*r;a+=v,b+=v; rTs;
    }
};

inline DB dot(cLine l1,cLine l2){return dot(l1.d(),l2.d());}
inline DB dot(cLine l,cPo p){return dot(l.a,l.b,p);}
inline DB dot(cPo p,cLine l){return dot(p,l.a,l.b);}
inline DB det(cLine l1,cLine l2){return det(l1.d(),l2.d());}
inline DB det(cLine l,cPo p){return det(l.a,l.b,p);}
inline DB det(cPo p,cLine l){return det(p,l.a,l.b);}
inline DB ang(cLine l0,cLine l1){return ang(l0.d(),l1.d());}
inline DB ang(cLine l,cPo p){return ang(l.a,l.b,p);}
inline DB ang(cPo p,cLine l){return ang(p,l.a,l.b);}

inline int Line::sgn(cLine l)const{return dett(Ts, l);}
inline Po Line::operator*(cLine l)const{return a+d()*det(a,l)/det(Ts,l);}
inline Po operator&(cPo p,cLine l){return l*Line(p,p+l.d().lt());}
inline Po operator%(cPo p,cLine l){return p&l*2-p;}
inline Line push(Line l, DB r){return l.push(r);}

struct Seg: public Line{
    Seg(cPo a=Po(),cPo b=Po()):Line(a,b){}
    Seg(DB x0,DB y0,DB x1,DB y1):Line(x0,y0,x1,y1){}
    Seg(cLine l):Line(l){}
    Seg(const Po &a,DB alpha):Line(a,alpha){}
    Seg(DB A,DB B,DB C):Line(A,B,C){}

    inline int sgn(cPo p)const;
    inline int sgn(cLine l)const;
    inline bool qrt(cSeg l)const;
    inline int sgn(cSeg l)const;
};

 // -1不相交 0相交（不规范） 1相交（规范）

inline int Seg::sgn(cPo p)const{return -dott(p,a,b);}
inline int Seg::sgn(cLine l)const{return sgn(Ts*l);}

// quick_rejection_test
inline bool Seg::qrt(cSeg l)const{
    return min(a.x,b.x)<=max(l.a.x,l.b.x)&&min(l.a.x,l.b.x)<=max(a.x,b.x)&&
        min(a.y,b.y)<=max(l.a.y,l.b.y)&&min(l.a.y,l.b.y)<=max(a.y,b.y);
}

inline int Seg::sgn(cSeg l)const{
    if (!qrt(l)) return -1;

    /*return
        (dett(a,b,l.a)*dett(a,b,l.b)<=0 &&
        dett(l.a,l.b,a)*dett(l.a,l.b,b)<=0)?1:-1;*/

    int d1=dett(a,b,l.a),d2=dett(a,b,l.b),d3=dett(l.a,l.b,a),d4=dett(l.a,l.b,b);
    if ((d1^d2)==-2&&(d3^d4)==-2)return 1;
    return ((!d1&&dott(l.a-a,l.a-b)<=0)||(!d2&&dott(l.b-a,l.b-b)<=0)||
            (!d3&&dott(a-l.a,a-l.b)<=0)||(!d4&&dott(b-l.a,b-l.b)<=0))?0:-1;
}

//inline DB dist2(cLine l,cPo p){return sqr(fabs(dot(lt(l.d()), p-l.a)))/l.len2();}
inline DB dist2(cLine l,cPo p){return sqr(fabs(det(l.d(), p-l.a)))/l.len2();}

inline DB dist2(cLine l1,cLine l2){return dett(l1,l2)?0:dist2(l1,l2.a);}

inline DB dist2(cSeg l,cPo p){
    Po pa = p - l.a, pb = p - l.b;
    if (dott(l.d(), pa) <= 0) return pa.len2();
    if (dott(l.d(), pb) >= 0) return pb.len2();
    return dist2(Line(l), p);
}

inline DB dist2(cSeg s,cLine l){
    Po v1=s.a-l.a,v2=s.b-l.a;DB d1=det(l.d(),v1),d2=det(l.d(),v2);
    return sgn(d1)!=sgn(d2) ? 0 : sqr(min(fabs(d1), fabs(d2)))/l.len2();
}
inline DB dist2(cSeg l1,cSeg l2){
    if (~l1.sgn(l2)) return 0;
    else return min(dist2(l2,l1.a), dist2(l2,l1.b), dist2(l1,l2.a), dist2(l1,l2.b));
}
template<class T1, class T2> inline DB dist2(const T1& a, const T2& b){
    return dist2(b, a);
}

} using namespace CG;//}

//}

/** I/O Accelerator Interface .. **/ //{
#define g (c=getchar())
#define d isdigit(g)
#define p x=x*10+c-'0'
#define n x=x*10+'0'-c
#define pp l/=10,p
#define nn l/=10,n
template<class T> inline T& RD(T &x){
    char c;while(!d);x=c-'0';while(d)p;
    return x;
}
template<class T> inline T& RDD(T &x){
    char c;while(g,c!='-'&&!isdigit(c));
    if (c=='-'){x='0'-g;while(d)n;}
    else{x=c-'0';while(d)p;}
    return x;
}
inline DB& RF(DB &x){
    //scanf("%lf", &x);
    char c;while(g,c!='-'&&c!='.'&&!isdigit(c));
    if(c=='-')if(g=='.'){x=0;DB l=1;while(d)nn;x*=l;}
        else{x='0'-c;while(d)n;if(c=='.'){DB l=1;while(d)nn;x*=l;}}
    else if(c=='.'){x=0;DB l=1;while(d)pp;x*=l;}
        else{x=c-'0';while(d)p;if(c=='.'){DB l=1;while(d)pp;x*=l;}}
    return x;
}
#undef nn
#undef pp
#undef n
#undef p
#undef d
#undef g
inline char* RS(char *s){
    //gets(s);
    scanf("%s", s);
    return s;
}

LL last_ans; int Case; template<class T> inline void OT(const T &x){
    printf("Cave %d: Oil capacity = %.0f\n", ++Case, x);
    //printf("%lld\n", x);
    //printf("%.9f\n", x);
    //printf("%d\n", x);
    //cout << x << endl;
    //last_ans = x;
    puts("");
}
//}

const int N = int(1e5)+9;

//}/* .................................................................................................................................. */

bool c[N];
VI x, y, r;

void in(int a,int b){
    c[a]=c[b]=1;
    x.PB(a),y.PB(b);
}

int main(){

#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#endif

    int n; DWN_1_C(i, RD(n), 2) if (!c[i]){
        // 2 4 6 3 6
        VI L; L.PB(i); for (int j=2*i;j<=n;j+=i) if (!c[j]) L.PB(j);
        if (SZ(L)==1){
            if (!(i&1)) c[L[0]]=1,r.PB(L[0]);
            continue;
        }
        if (SZ(L)&1){
            FOR(j, 2, SZ(L)-1) in(L[j],L[j+1]),++j;
            in(L[0],L.back()); c[L[1]]=1,r.PB(L[1]);
        }
        else{
            REP(j, SZ(L)){
                in(L[j],L[j+1]),++j;
            }
        }
    }
    REP(i, SZ(r)-1){
        in(r[i],r[i+1]),++i;
    }

    cout << SZ(x) << endl;
    REP(i, SZ(x)){cout <<x[i] << " " <<y[i]<<endl;}
}


#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
using namespace std;

set< pair<int, int > > cur[100500];
set< pair<int, int> > all;

int main() {
    int n;
    cin >> n;
    for(int i = 2; i <= n; i++) {
        int t = i;
        vector<int> divs;
        for(int j = 2; j * j <= t; j++) {
            if(t % j)
                continue;
            divs.push_back(j);
            while((t % j) == 0)
                t /= j;
        }
        if(t > 1)
            divs.push_back(t);
        int sz = divs.size();
        pair<int, int> add = make_pair(sz, i);
        for(int j = 0; j < sz; j++) {
            cur[divs[j]].insert(add);
        }
        all.insert(add);
    }

    vector< pair<int, int> > ans;
    for(int i = 0; i < n - 1; i++) {
        pair<int, int> peek = *all.begin();
        all.erase(peek);
        int t = peek.second;
        int best = -1;
        for(int j = 2; j * j <= t; j++) {
            if(t % j)
                continue;
            cur[j].erase(peek);
            if(!cur[j].empty() and (best == -1 or cur[j].begin()->first <
                        cur[best].begin()->first))
                best = j;
            while((t % j) == 0)
                t /= j;
        }
        if(t > 1) {
            cur[t].erase(peek);
            if(!cur[t].empty() and (best == -1 or cur[t].begin()->first <
                        cur[best].begin()->first))
                best = t;
        }
        if(best == -1)
            continue;

        ans.push_back(make_pair(peek.second, cur[best].begin()->second));
        pair<int, int> g = *cur[best].begin();
        t = cur[best].begin()->second;
        for(int j = 2; j * j <= t; j++) {
            if(t % j)
                continue;
            while((t % j) == 0)
                t /= j;
            cur[j].erase(g);
        }
        if(t > 1)
            cur[t].erase(g);
        all.erase(g);
        cur[best].erase(g);
    }
    cout << ans.size() << "\n";
    for(int i = 0; i < ans.size(); i++)
        cout << ans[i].first << " " << ans[i].second << "\n";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
#define maxn 100100

int N;
bool viz[maxn], isPrime[maxn];
int nrDiv[maxn];

vector<int> aux;
vector< pair<int, int> > sol;

int cmp(int a, int b) {
    return nrDiv[a] < nrDiv[b];
}

int gcd(int a, int b) {
    if(!b) {
        return a;
    }

    return gcd(b, a%b);
}

void computePrimes() {
    for(int i=2; i<=N; i++) {
        if(!viz[i]) {
            isPrime[i] = true;

            for(int j=i; j<=N; j+=i) {
                viz[j] = true;
            }
        }
    }
}

void computeNrDiv() {
    for(int i=2; i<=N; i++) {
        int rad = sqrt(i);

        for(int j=1; j<=rad; j++) {
            if(i % j == 0) {
                nrDiv[i] ++;

                if(j != i/j) {
                    nrDiv[i] ++;
                }
            }
        }
    }
}

int main() {
    cin >> N;

    computePrimes();

    computeNrDiv();

    for(int i=2; i<=N; i++) {
        aux.push_back(i);
    }

    sort(aux.begin(), aux.end(), cmp);

    memset(viz, 0, sizeof(viz));
    for(int i=0; i<aux.size(); i++) {
        if(viz[i]) continue;

        for(int j=i+1; j<aux.size(); j++) {
            if(!viz[j] && gcd(aux[i], aux[j]) > 1) {
                sol.push_back( make_pair(aux[i], aux[j]) );

                viz[i] = true;
                viz[j] = true;

                break;
            }
        }
    }

    cout << sol.size() << '\n';
    for(int i=0; i<sol.size(); i++) {
        cout << sol[i].first << ' ' << sol[i].second << '\n';
    }

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
#define maxn 100100

int N;
bool viz[maxn];
int nrDiv[maxn];

vector<int> aux;
vector<int> numbers[maxn];
vector< pair<int, int> > sol;

int cmp(int a, int b) {
    return nrDiv[a] < nrDiv[b];
}

int gcd(int a, int b) {
    if(!b) {
        return a;
    }

    return gcd(b, a%b);
}

void computeNrDiv() {
    for(int i=2; i<=N; i++) {
        int rad = sqrt(i);

        for(int j=1; j<=rad; j++) {
            if(i % j == 0) {
                nrDiv[i] ++;

                if(j != i/j) {
                    nrDiv[i] ++;
                }
            }
        }
    }
}

void tryRemove(int j) {
    vector<int>::iterator it;

    while(numbers[j].size()) {
        it = numbers[j].end(); it --;

        if(viz[*it]) {
            numbers[j].pop_back();
        }
        else break;
    }
}

int main() {
    cin >> N;

    computeNrDiv();
    nrDiv[0] = 99999999;

    for(int i=2; i<=N; i++) {
        aux.push_back(i);
    }

    sort(aux.begin(), aux.end(), cmp);

    for(int i=aux.size()-1; i>0; i--) {
        int rad = sqrt(aux[i]);

        for(int j=1; j<=rad; j++) {
            if(aux[i] % j == 0) {
                if(j > 1) numbers[j].push_back(aux[i]);

                if(j != aux[i]/j) {
                    if(aux[i]/j > 1) numbers[aux[i]/j].push_back(aux[i]);
                }
            }
        }
    }

    vector<int>::iterator it;
    int used_nr = 0;

    for(int i=0; i<aux.size(); i++) {
        if(viz[ aux[i] ]) continue;

        int which_who = -1;

        int rad = sqrt(aux[i]);
        for(int j=1; j<=rad; j++) {
            if(aux[i] % j == 0) {
                tryRemove(j);
                if(numbers[j].size()) {
                    it = numbers[j].end(); it --;
                    used_nr = (*it);

                    if((*it) == aux[i]) {
                        numbers[j].pop_back();
                        tryRemove(j);
                        if(numbers[j].size()) {
                            it = numbers[j].end(); it --;
                            numbers[j].push_back(used_nr);
                            used_nr = (*it);
                        }
                        else {
                            numbers[j].push_back(used_nr);
                            used_nr = 0;
                        }
                    }

                    if(which_who == -1 || nrDiv[used_nr] < nrDiv[which_who]) {
                        which_who = used_nr;
                    }
                }

                if(j != aux[i] / j) {
                    tryRemove(aux[i] / j);
                    if(numbers[aux[i] / j].size()) {
                        it = numbers[aux[i] / j].end(); it --;
                        used_nr = (*it);

                        if((*it) == aux[i]) {
                            numbers[aux[i]/j].pop_back();
                            tryRemove(aux[i]/j);
                            if(numbers[aux[i]/j].size()) {
                                it = numbers[aux[i]/j].end(); it --;
                                numbers[aux[i]/j].push_back(used_nr);
                                used_nr = (*it);
                            }
                            else {
                                numbers[aux[i]/j].push_back(used_nr);
                                used_nr = 0;
                            }
                        }

                        if(which_who == -1 || nrDiv[used_nr] < nrDiv[which_who]) {
                            which_who = used_nr;
                        }
                    }
                }
            }
        }

        if(which_who > 0) {
            viz[ aux[i] ] = true;
            viz[which_who] = true;

            sol.push_back( make_pair(aux[i], which_who) );
        }
    }

    cout << sol.size() << '\n';
    for(int i=0; i<sol.size(); i++) {
        cout << sol[i].first << ' ' << sol[i].second << '\n';
    }

    return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <set>
#include <vector>
#include <cassert>
using namespace std;
const int N=1e5+2,inf=0x3f3f3f3f;
bool v[N];
int n;
vector<int> p;
void pre(int n)
{
	for(int i=2;i<=n;i++)
	if(!v[i])
	{
		p.push_back(i);
		int k=i<<1;
		while(k<=n) v[k]=1,k+=i;

	}
}
#define mp make_pair
typedef pair<int,int> pii;
vector<pii> ans;
int main()
{
	cin>>n;
	pre(n);
	memset(v,0,sizeof(v));
	for(int i=n;i-1;i--)
	{
		int k=i;
		int nk=k<<1;
		while(nk<=n)
		{
			// printf("%d :%d\n",nk,v[nk]);
			if(v[nk]) nk+=i;
			else
			{
				ans.push_back(mp(k,nk));
				v[k]=1;
				v[nk]=1;
				k=nk+i;

				while(k<=n&&v[k]) k+=i;
				if(k>n) break;
				nk=k+i;
			}
		}
	}
	cout<<ans.size()<<endl;
	for(int i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
	return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <set>
#include <vector>
#include <cassert>
using namespace std;
const int N=1e5+2,inf=0x3f3f3f3f;
bool v[N];
int n;
vector<int> p;
int bas[N];
void pre(int n)
{
	for(int i=2;i<=n;i++)
	if(!v[i])
	{
		p.push_back(i);
		int k=i<<1;
		while(k<=n) v[k]=1,k+=i;

	}
	for(int i=2;i<=n;i++)
	{
		int k=0,t=i;
		for(int j=0;p[j]*p[j]<=i;j++)
		if(i%p[j]==0)
		{
			k++;
			while(t%p[j]==0)t/=p[j];
			break;
		}
		if(k==0||t==1) bas[i]=1;
	}
}
#define mp make_pair
typedef pair<int,int> pii;
vector<pii> ans;
bool cmp(int x,int y)
{
	return bas[x]>bas[y];
}
int main()
{
	cin>>n;
	pre(n);
	memset(v,0,sizeof(v));
	for(int i=int(p.size())-1;i+1;i--)
	{
		int k=p[i];
		vector<int> a;
		while(k<=n)
		{
			if(v[k]==0) a.push_back(k);
			k+=p[i];
		}
		sort(a.begin(),a.end(),cmp);
		for(int i=0;i+1<a.size();i+=2)
		{
			v[a[i]]=1;
			v[a[i+1]]=1;
			ans.push_back(mp(a[i],a[i+1]));
		}
	}
	cout<<ans.size()<<endl;
	for(int i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
	return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <set>
#include <vector>
#include <cassert>
using namespace std;
const int N=1e5+2,inf=0x3f3f3f3f;
bool v[N];
int n;
vector<int> p;
int bas[N];
void pre(int n)
{
	for(int i=2;i<=n;i++)
	if(!v[i])
	{
		p.push_back(i);
		int k=i<<1;
		while(k<=n) v[k]=1,k+=i;

	}
	for(int i=2;i<=n;i++)
	{
		for(int j=0;p[j]*p[j]<=i;j++)
		if(i%p[j]==0)
		{
			bas[i]=p[j];
			break;
		}
		if(bas[i]==0) bas[i]=i;
	}
}
#define mp make_pair
typedef pair<int,int> pii;
vector<pii> ans;
bool cmp(int x,int y)
{
	return bas[x]>bas[y];
}
int main()
{
	cin>>n;
	pre(n);
	memset(v,0,sizeof(v));
	for(int i=int(p.size())-1;i+1;i--)
	{
		int k=p[i];
		vector<int> a;
		while(k<=n)
		{
			if(v[k]==0) a.push_back(k);
			k+=p[i];
		}
		sort(a.begin(),a.end(),cmp);
		for(int i=0;i+1<a.size();i+=2)
		{
			v[a[i]]=1;
			v[a[i+1]]=1;
			ans.push_back(mp(a[i],a[i+1]));
		}
	}
	cout<<ans.size()<<endl;
	for(int i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
	return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <set>
#include <vector>
#include <cassert>
using namespace std;
const int N=1e5+2,inf=0x3f3f3f3f;
bool v[N];
int n;
vector<int> p;
void pre(int n)
{
	for(int i=2;i<=n;i++)
	if(!v[i])
	{
		p.push_back(i);
		int k=i<<1;
		while(k<=n) v[k]=1,k+=i;

	}
}
#define mp make_pair
typedef pair<int,int> pii;
vector<pii> ans;
int main()
{
	cin>>n;
	pre(n);
	memset(v,0,sizeof(v));
	for(int i=0;i<p.size();i++)
	{
		int k=p[i];
		int nk=k<<1;
		while(nk<=n)
		{
			// printf("%d :%d\n",nk,v[nk]);
			if(v[nk]) nk+=p[i];
			else
			{
				ans.push_back(mp(k,nk));
				v[k]=1;
				v[nk]=1;
				k=nk+p[i];
				while(k<=n&&v[k]) k+=p[i];
				if(k>n) break;
				nk=k+p[i];
			}
		}
	}
	cout<<ans.size()<<endl;
	for(int i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int maxN = 100*1000 + 5;
vector<int> a[maxN];
int mark[maxN];
int p[maxN];
int main()
{
    int n; cin >> n;
    for(int i = 2; i <= n; i ++)
	  if(!mark[i])
		for(int j = i; j <= n; j += i)
		    if(!mark[j]) a[i].push_back(j), mark[j] = 1;
    memset(p, -1, sizeof p);
    int cnt = 0;
    vector<int> r;
    for(int i = 2; i <= n; i ++)
    {
	  if(a[i].size() & 1) r.push_back(i);
	  for(int j = a[i].size() % 2; j < a[i].size(); j += 2)
	  {
		int v = a[i][j], u = a[i][j + 1];
		p[v] = u; p[u] = v; cnt ++;
	  }
    }
    //for(int i = 1; i <= n; i ++)
//	  cout << p[i] << ' '; cout << endl;
    int st = r.size() - 1;
    for(int i = 0; i < r.size(); i ++)
    {
//	  cout << i << ' ' << st << endl;
	  while(r[st] * r[i] > n && st > i) st --;
	  if(st <= i) break;
	  int v = r[st], u = r[i], x = u * v;
//	  cout << v << ' ' << u << ' ' << st  << endl;
	  p[u] = p[x]; p[p[u]] = u;
	  p[x] = v; p[v] = x; cnt ++; st --;
    }
    cout << cnt << endl;
    vector< pair<int, int> > ans;
    for(int i = 1; i <= n; i ++)
    {
	  if(p[i] == -1) continue;
	  p[p[i]] = -1;
	  ans.push_back(make_pair(i, p[i]));
    }
    for(int i = 0; i < ans.size(); i ++)
	  cout << ans[i].first << ' ' << ans[i].second << endl;
}


//ITNOG
#include <bits/stdc++.h>

using namespace std;
const int maxN = 100*1000 + 5;
vector<int> a[maxN];
int mark[maxN];
int main()
{
    int n; cin >> n;
    for(int i = 3; i <= n / 2; i ++)
	  if(!mark[i])
		for(int j = i; j <= n; j += i)
		    if(!mark[j]) a[i].push_back(j), mark[j] = 1;
    vector<pair<int, int> > ans;
    vector<int> r;
    memset(mark, 0, sizeof mark);
    for(int i = 3; i <= n / 2; i ++)
    {
	  if(a[i].size() & 1)
	  {
		ans.push_back(make_pair(a[i][0], a[i][2])); mark[a[i][0]] = 1; mark[a[i][2]] = 1;
		for(int j = 3; j < a[i].size(); j += 2)
		{
		    ans.push_back(make_pair(a[i][j], a[i][j + 1]));
		    mark[a[i][j]] = mark[a[i][j + 1]] = 1;
		}
	  }
	  else
		for(int j = 0; j < a[i].size(); j += 2)
		    ans.push_back(make_pair(a[i][j], a[i][j + 1])), mark[a[i][j]] = mark[a[i][j + 1]] = 1;
    }
    for(int i = 2; i <= n; i += 2)
	  if(!mark[i]) r.push_back(i);
    for(int i = 0; i < (r.size() / 2) * 2; i += 2)
	  ans.push_back(make_pair(r[i], r[i + 1]));
    cout << ans.size() << endl;
    for(auto u : ans)
	  cout << u.first << ' ' << u.second << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iterator>
#include <ctime>
#include <iomanip>
#include <tuple>

typedef unsigned int uint32;
typedef signed long long int64;
typedef unsigned long long uint64;

using namespace std;

#define ALL(a) a.begin(), a.end()
#define FOR(a) for (int i = 0; i < (a); ++i)
#define D(a) #a << ": " << a << "\n"

int main()
{
    int n;
    cin >> n;

    vector<int> sieve(n/2+1, 1);
    for (int i = 2; i <= n / 2; ++i)
        if (sieve[i])
        {
            int mul = 2;
            while (mul * i <= n / 2)
                sieve[mul*i] = 0,
                ++mul;
        }

    vector<int> primes;
    for (int i = 2; i <= n / 2; ++i)
        if (sieve[i])
            primes.push_back(i);

    vector<pair<int, int> > res;

    vector<int> skipped;
    for (int i = 1; i < primes.size(); ++i)
    {
        int mul = 1;
        int idx = 1;
        vector<int> good;

        while (primes[i] * mul <= n)
        {
            if (primes[idx] < primes[i] && primes[idx] == mul)
                ++idx;
            else
                good.push_back(mul * primes[i]);

            ++mul;
        }

        int start = 0;
        if (good.size() % 2)
        {
            start = 3;
            if (good.size() > 1)
            {
                res.push_back({ good[0], good[2] });
                skipped.push_back(good[1]);
            }

        }

        for (; start < good.size(); start += 2)
            res.push_back({ good[start], good[start + 1] });
    }

    // 2
    int mul = 1;
    int idx = 1;
    vector<int> good;

    while (2 * mul <= n)
    {
        if (idx < primes.size() && primes[idx] == mul)
            ++idx;
        else
            good.push_back(mul * 2);

        ++mul;
    }

    for (int a : skipped) good.push_back(a);

    for (int start = 0; start+1 < good.size(); start += 2)
        res.push_back({ good[start], good[start + 1] });

    cout << res.size() << endl;
    for (auto a : res)
        printf("%d %d\n", a.first, a.second);
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iterator>
#include <ctime>
#include <iomanip>
#include <tuple>

typedef unsigned int uint32;
typedef signed long long int64;
typedef unsigned long long uint64;

using namespace std;

#define ALL(a) a.begin(), a.end()
#define FOR(a) for (int i = 0; i < (a); ++i)
#define D(a) #a << ": " << a << "\n"

int main()
{
    int n;
    cin >> n;

    vector<int> sieve(n/2+1, 1);
    for (int i = 2; i <= n / 2; ++i)
        if (sieve[i])
        {
            int mul = 2;
            while (mul * i <= n / 2)
                sieve[mul*i] = 0,
                ++mul;
        }

    vector<int> primes;
    for (int i = 2; i <= n / 2; ++i)
        if (sieve[i])
            primes.push_back(i);

    vector<pair<int, int> > res;

    set<int> used;
    vector<int> skipped;
    for (int i = 1; i < primes.size(); ++i)
    {
        int mul = 1;
        vector<int> good;

        while (primes[i] * mul <= n)
        {
            if (used.count(mul * primes[i]))
                ;
            else
                good.push_back(mul * primes[i]),
                used.insert(mul * primes[i]);

            ++mul;
        }

        int start = 0;
        if (good.size() % 2)
        {
            start = 3;
            if (good.size() > 1)
            {
                res.push_back({ good[0], good[2] });
                skipped.push_back(good[1]);
            }

        }

        for (; start < good.size(); start += 2)
            res.push_back({ good[start], good[start + 1] });
    }

    // 2
    int mul = 1;
    vector<int> good;

    while (2 * mul <= n)
    {
        if (used.count(2*mul))
            ;
        else
            good.push_back(mul * 2);

        ++mul;
    }

    for (int a : skipped) good.push_back(a);

    for (int start = 0; start+1 < good.size(); start += 2)
        res.push_back({ good[start], good[start + 1] });

    cout << res.size() << endl;
    for (auto a : res)
        printf("%d %d\n", a.first, a.second);
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <bitset>

using namespace std;

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
template <typename T> void print_container(ostream& os, const T& c) { const char* _s = " "; if (!c.empty()) { __typeof__(c.begin()) last = --c.end(); foreach (it, c) { os << *it; if (it != last) os << _s; } } }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& c) { print_container(os, c); return os; }
template <typename T> ostream& operator<<(ostream& os, const set<T>& c) { print_container(os, c); return os; }
template <typename T> ostream& operator<<(ostream& os, const multiset<T>& c) { print_container(os, c); return os; }
template <typename T> ostream& operator<<(ostream& os, const deque<T>& c) { print_container(os, c); return os; }
template <typename T, typename U> ostream& operator<<(ostream& os, const map<T, U>& c) { print_container(os, c); return os; }
template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }

template <typename T> void print(T a, int n, const string& split = " ") { for (int i = 0; i < n; i++) { cout << a[i]; if (i + 1 != n) cout << split; } cout << endl; }
template <typename T> void print2d(T a, int w, int h, int width = -1, int br = 0) { for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (width != -1) cout.width(width); cout << a[i][j] << ' '; } cout << endl; } while (br--) cout << endl; }
template <typename T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
#define dump(v) (cerr << #v << ": " << v << endl)

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define erep(i, n) for (int i = 0; i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define clr(a, x) memset(a, x, sizeof(a))
#define sz(a) ((int)(a).size())
#define mp(a, b) make_pair(a, b)
#define ten(n) ((long long)(1e##n))

template <typename T, typename U> void upmin(T& a, const U& b) { a = min<T>(a, b); }
template <typename T, typename U> void upmax(T& a, const U& b) { a = max<T>(a, b); }
template <typename T> void uniq(T& a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }
template <class T> string to_s(const T& a) { ostringstream os; os << a; return os.str(); }
template <class T> T to_T(const string& s) { istringstream is(s); T res; is >> res; return res; }
void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }
bool in_rect(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }

typedef long long ll;
typedef pair<int, int> pint;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };

vector<bool> prime_table(int upto)
{
    vector<bool> p(upto + 1, true);
    p[0] = p[1] = false;
    for (int i = 2; i * i <= upto; ++i)
        if (p[i])
            for (int j = i + i; j <= upto; j += i)
                p[j] = false;
    return p;
}
vector<int> primes(int upto, const vector<bool>& p = prime_table(0))
{
    if ((int)p.size() <= upto)
        return primes(upto, prime_table(upto));

    vector<int> primes;
    for (int i = 0; i <= upto; ++i)
        if (p[i])
            primes.push_back(i);
    return primes;
}
int main()
{
    int n;
    cin >> n;

    const int M = ten(6) + 810;
    bool used[M] = {};
    vector<int> ps = primes(n);
    reverse(all(ps));
    vector<pint> res;
    for (int p : ps)
    {
        static vector<int> a;
        a.clear();
        for (int i = p; i <= n; i += p)
            if (!used[i] && (i != 2 * p || p == 2 || n / p % 2 == 0))
                a.push_back(i);

        for (int i = 0; i + 1 < (int)a.size(); i += 2)
        {
            used[a[i]] = used[a[i + 1]] = true;
            res.push_back(pint(a[i], a[i + 1]));
        }
    }
    printf("%d\n", (int)res.size());
    for (auto& it : res)
        printf("%d %d\n", it.first, it.second);
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <bitset>

using namespace std;

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
template <typename T> void print_container(ostream& os, const T& c) { const char* _s = " "; if (!c.empty()) { __typeof__(c.begin()) last = --c.end(); foreach (it, c) { os << *it; if (it != last) os << _s; } } }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& c) { print_container(os, c); return os; }
template <typename T> ostream& operator<<(ostream& os, const set<T>& c) { print_container(os, c); return os; }
template <typename T> ostream& operator<<(ostream& os, const multiset<T>& c) { print_container(os, c); return os; }
template <typename T> ostream& operator<<(ostream& os, const deque<T>& c) { print_container(os, c); return os; }
template <typename T, typename U> ostream& operator<<(ostream& os, const map<T, U>& c) { print_container(os, c); return os; }
template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }

template <typename T> void print(T a, int n, const string& split = " ") { for (int i = 0; i < n; i++) { cout << a[i]; if (i + 1 != n) cout << split; } cout << endl; }
template <typename T> void print2d(T a, int w, int h, int width = -1, int br = 0) { for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (width != -1) cout.width(width); cout << a[i][j] << ' '; } cout << endl; } while (br--) cout << endl; }
template <typename T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
#define dump(v) (cerr << #v << ": " << v << endl)

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define erep(i, n) for (int i = 0; i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define clr(a, x) memset(a, x, sizeof(a))
#define sz(a) ((int)(a).size())
#define mp(a, b) make_pair(a, b)
#define ten(n) ((long long)(1e##n))

template <typename T, typename U> void upmin(T& a, const U& b) { a = min<T>(a, b); }
template <typename T, typename U> void upmax(T& a, const U& b) { a = max<T>(a, b); }
template <typename T> void uniq(T& a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }
template <class T> string to_s(const T& a) { ostringstream os; os << a; return os.str(); }
template <class T> T to_T(const string& s) { istringstream is(s); T res; is >> res; return res; }
void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }
bool in_rect(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }

typedef long long ll;
typedef pair<int, int> pint;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };

vector<bool> prime_table(int upto)
{
    vector<bool> p(upto + 1, true);
    p[0] = p[1] = false;
    for (int i = 2; i * i <= upto; ++i)
        if (p[i])
            for (int j = i + i; j <= upto; j += i)
                p[j] = false;
    return p;
}
vector<int> primes(int upto, const vector<bool>& p = prime_table(0))
{
    if ((int)p.size() <= upto)
        return primes(upto, prime_table(upto));

    vector<int> primes;
    for (int i = 0; i <= upto; ++i)
        if (p[i])
            primes.push_back(i);
    return primes;
}
int main()
{
    int n;
    cin >> n;

    const int M = ten(6) + 810;
    bool used[M] = {};
    vector<int> ps = primes(n);
    reverse(all(ps));
    vector<pint> res;
    for (int p : ps)
    {
        static vector<int> a;
        a.clear();
        for (int i = p; i <= n; i += p)
            if (!used[i])
                a.push_back(i);
        if (a.size() >= 2 && (a.size() & 1))
            a.erase(a.end() - 1 - (a.back() & 1));

        for (int i = 0; i + 1 < (int)a.size(); i += 2)
        {
            used[a[i]] = used[a[i + 1]] = true;
            res.push_back(pint(a[i], a[i + 1]));
        }
    }
    printf("%d\n", (int)res.size());
    for (auto& it : res)
        printf("%d %d\n", it.first, it.second);
}


#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cassert>
#include <string>
#include <vector>
#include <cstdio>
#include <set>
#include <map>
#include <queue>
#include <memory.h>
#include <cmath>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define fore(i, b, e) for (int i = (int)b; i <= (int)e; i++)
#define all(x) (x).begin(), (x).end()
#define se second
#define fi first
#define mp make_pair
#define pb push_back
#define op operator
typedef vector <int> vi;
typedef pair<int, int> pii;
typedef long long i64;

const int maxn = 1e5 + 5;

vector <pii> ans;
bool used[maxn];
int max_d[maxn];
int n;

inline void add(int x, int y)
{
	ans.pb(mp(x, y));
	used[x] = used[y] = true;
}

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%d", &n);
	fore(i, 2, n) if (max_d[i] == 0)
	{
		for (int j = 2 * i; j <= n; j += i)
			max_d[j] = i;
	}
	fore(prime, 2, n) if (max_d[prime] == 0)
	{
		vi list1;
		list1.pb(prime);
		vi list2;
		for (int j = 2 * prime; j <= n; j += prime) if (!used[j])
		{
			if (max_d[j] == prime)
				list1.pb(j);
			else list2.pb(j);
		}
		for (int h = 0; h + 1 < list1.size(); h += 2)
			add(list1[h], list1[h + 1]);
		int start;
		if (list1.size() % 2 == 1 && !list2.empty())
		{
			add(list1.back(), list2[0]);
			start = 1;
		}
		else start = 0;
		for (int h = start; h + 1 < list2.size(); h += 2)
			add(list2[h], list2[h + 1]);
	}
	printf("%d\n", ans.size());
	forn(j, ans.size())
		printf("%d %d\n", ans[j].fi, ans[j].se);

	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cassert>
#include <string>
#include <vector>
#include <cstdio>
#include <set>
#include <map>
#include <queue>
#include <memory.h>
#include <cmath>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define fore(i, b, e) for (int i = (int)b; i <= (int)e; i++)
#define all(x) (x).begin(), (x).end()
#define se second
#define fi first
#define mp make_pair
#define pb push_back
#define op operator
typedef vector <int> vi;
typedef pair<int, int> pii;
typedef long long i64;

const int maxn = 1e5 + 5;

vector <pii> ans;
bool used[maxn];
int max_d[maxn];
vi spec;
int n;

inline void add(int x, int y)
{
	ans.pb(mp(x, y));
	used[x] = used[y] = true;
}

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%d", &n);
	fore(i, 2, n) if (max_d[i] == 0)
	{
		for (int j = 2 * i; j <= n; j += i)
			max_d[j] = i;
	}
	for (int prime = n; prime >= 2; prime--) if (max_d[prime] == 0)
	{
		vi list;
		list.pb(prime);
		for (int j = 2 * prime; j <= n; j += prime) if (!used[j])
		{
			list.pb(j);
		}
		if (list.size() % 2 == 1)
		{
			forn(chosen, list.size())
				if (list[chosen] % 2 == 0)
				{
					spec.pb(list[chosen]);
					used[list[chosen]] = true;
					list.erase(list.begin() + chosen);
					break;
				}
		}
		forn(i, list.size() / 2)
			add(list[i * 2], list[i * 2 + 1]);
	}
	forn(j, spec.size() / 2)
		add(spec[j * 2], spec[j * 2 + 1]);
	printf("%d\n", ans.size());
	forn(j, ans.size())
		printf("%d %d\n", ans[j].fi, ans[j].se);

	return 0;
}


// Author: bill125

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <bitset>
#include <cmath>
#include <stack>

using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> Pair;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repD(i, n) for (int i = n - 1; i >= 0; --i)
#define For(i, a, b) for (int i = a; i <= b; ++i)
#define ForD(i, a, b) for (int i = a; i >= b; --i)
#define ForE(i, a) for (Edge* i = h[a]; i; i = i->next)
#define forv(i, a) for (unsigned int i = 0, ___t = a.size(); i < ___t; ++i)
#define ForV(i, a) for (__typeof(a.begin()) i = a.begin();i != a.end(); ++i)
#define fill(a, b) memset(a, b, sizeof(a))
#define lowbit(a) ((a) & (-(a)))
#define sqr(a) ((a)*(a))
#define pb push_back
#define mp make_pair
#define gi gI()
#define cut puts("===================")

void setIO(string NAME) {
	#ifndef ONLINE_JUDGE
	string in=NAME+".in", out=NAME+".out";freopen(in.c_str(),"r",stdin),freopen(out.c_str(),"w",stdout);
	#endif
}
inline ll gI() {char c=getchar();while ((c<'0' || c>'9')&&c!='-') c=getchar();ll flag=1,p=0;if (c=='-') flag=-1,c=getchar();while (c>='0' && c<='9') p=p*10+(c-'0'),c=getchar();return p*flag;}
int gs(char *C) {char c=getchar();while (c==' ' || c=='\n') c=getchar();int l=0;while (c!=' ' && c!='\n' && c!=EOF) C[l++]=c,c=getchar();C[l]=0;return l;}
template <class T> void debug (const T a,const int & n) {rep(i,n) printf("%d%c", a[i],(i==n-1)?'\n':' ');}

const int inf = ~0U>>1, maxn = 1000000 + 10;
int n, pcnt = 0;
int prime[maxn];
bool vis[maxn];
vector<pair<int, int> >ans_p;

int main() {
	setIO("test");

	n = gi;

	for (int i = 2; i <= n; ++ i) if (!vis[i]) {
		for (int j = i << 1; j <= n; j += i) vis[j] = 1;
		prime[pcnt ++] = i;
	}
	fill(vis, 0);
	int last = -1;
	rep(i, pcnt) {
		last = -1;
		for (int j = prime[i]; j <= n; j += prime[i]) {
			if (!vis[j]) {
			//	printf("%d ", j);
				if (last == -1) last = j;
				else {
					ans_p.push_back(make_pair(last, j));
					vis[j] = vis[last] = 1;
					last = -1;
				}
			}
		}
	//	puts("");
	}
	int ans = ans_p.size();
	printf("%d\n", ans);
	rep(i, ans) printf("%d %d\n", ans_p[i].first, ans_p[i].second);
	return 0;
}


// Author: bill125

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <bitset>
#include <cmath>
#include <stack>

using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> Pair;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repD(i, n) for (int i = n - 1; i >= 0; --i)
#define For(i, a, b) for (int i = a; i <= b; ++i)
#define ForD(i, a, b) for (int i = a; i >= b; --i)
#define ForE(i, a) for (Edge* i = h[a]; i; i = i->next)
#define forv(i, a) for (unsigned int i = 0, ___t = a.size(); i < ___t; ++i)
#define ForV(i, a) for (__typeof(a.begin()) i = a.begin();i != a.end(); ++i)
#define fill(a, b) memset(a, b, sizeof(a))
#define lowbit(a) ((a) & (-(a)))
#define sqr(a) ((a)*(a))
#define pb push_back
#define mp make_pair
#define gi gI()
#define cut puts("===================")

void setIO(string NAME) {
	#ifndef ONLINE_JUDGE
	string in=NAME+".in", out=NAME+".out";freopen(in.c_str(),"r",stdin),freopen(out.c_str(),"w",stdout);
	#endif
}
inline ll gI() {char c=getchar();while ((c<'0' || c>'9')&&c!='-') c=getchar();ll flag=1,p=0;if (c=='-') flag=-1,c=getchar();while (c>='0' && c<='9') p=p*10+(c-'0'),c=getchar();return p*flag;}
int gs(char *C) {char c=getchar();while (c==' ' || c=='\n') c=getchar();int l=0;while (c!=' ' && c!='\n' && c!=EOF) C[l++]=c,c=getchar();C[l]=0;return l;}
template <class T> void debug (const T a,const int & n) {rep(i,n) printf("%d%c", a[i],(i==n-1)?'\n':' ');}

const int inf = ~0U>>1, maxn = 1000000 + 10;
int n, pcnt = 0;
int prime[maxn];
bool vis[maxn];
vector<pair<int, int> >ans;
vector<int> now_p;

int main() {
	setIO("test");

	n = gi;
	For(i, 2, n) if (!vis[i]) {
		prime[pcnt ++] = i;
		for (int j = i; j <= n; j += i) vis[j] = 1;
	}
	//debug(prime, pcnt);
	fill(vis, 0);

	repD(i, pcnt) {
		now_p.clear();
		for (int j = prime[i]; j <= n; j += prime[i]) if (!vis[j])
			now_p.push_back(j);

		if (now_p.size() == 1) continue;
		if (now_p.size() & 1) swap(now_p[1], now_p[now_p.size() - 1]);

		repD(j, now_p.size() / 2) {
			vis[now_p[j * 2]] = vis[now_p[j * 2 + 1]] = 1;
			ans.push_back(make_pair(now_p[j * 2], now_p[j * 2 + 1]));
		}
	}

	//int ans = ans_p.size();
	printf("%d\n", ans.size());
	forv(i, ans) printf("%d %d\n", ans[i].first, ans[i].second);
	return 0;
}


// Author: bill125

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <bitset>
#include <cmath>
#include <stack>

using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> Pair;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repD(i, n) for (int i = n - 1; i >= 0; --i)
#define For(i, a, b) for (int i = a; i <= b; ++i)
#define ForD(i, a, b) for (int i = a; i >= b; --i)
#define ForE(i, a) for (Edge* i = h[a]; i; i = i->next)
#define forv(i, a) for (unsigned int i = 0, ___t = a.size(); i < ___t; ++i)
#define ForV(i, a) for (__typeof(a.begin()) i = a.begin();i != a.end(); ++i)
#define fill(a, b) memset(a, b, sizeof(a))
#define lowbit(a) ((a) & (-(a)))
#define sqr(a) ((a)*(a))
#define pb push_back
#define mp make_pair
#define gi gI()
#define cut puts("===================")

void setIO(string NAME) {
	#ifndef ONLINE_JUDGE
	string in=NAME+".in", out=NAME+".out";freopen(in.c_str(),"r",stdin),freopen(out.c_str(),"w",stdout);
	#endif
}
inline ll gI() {char c=getchar();while ((c<'0' || c>'9')&&c!='-') c=getchar();ll flag=1,p=0;if (c=='-') flag=-1,c=getchar();while (c>='0' && c<='9') p=p*10+(c-'0'),c=getchar();return p*flag;}
int gs(char *C) {char c=getchar();while (c==' ' || c=='\n') c=getchar();int l=0;while (c!=' ' && c!='\n' && c!=EOF) C[l++]=c,c=getchar();C[l]=0;return l;}
template <class T> void debug (const T a,const int & n) {rep(i,n) printf("%d%c", a[i],(i==n-1)?'\n':' ');}

const int inf = ~0U>>1, maxn = 1000000 + 10;
int n, pcnt = 0;
int prime[maxn];
bool vis[maxn];
vector<pair<int, int> >ans_p;

int main() {
	setIO("test");

	n = gi;

	for (int i = 2; i <= n; ++ i) if (!vis[i]) {
		for (int j = i << 1; j <= n; j += i) vis[j] = 1;
		prime[pcnt ++] = i;
	}
	fill(vis, 0);
	For(i, 1, pcnt) {
		if (prime[i] * 2 > n) break;
		ans_p.push_back(mp(prime[i], prime[i] * 2));
		vis[prime[i]]=vis[prime[i]*2] =1;
	}

	int last = -1;
	rep(i, pcnt) {
		last = -1;
		for (int j = prime[i]; j <= n; j += prime[i]) {
			if (!vis[j]) {
				if (last == -1) last = j;
				else {
					ans_p.push_back(make_pair(last, j));
					vis[j] = vis[last] = 1;
					last = -1;
				}
			}
		}
	}
	//For(i, 1, n) if (!vis[i]) printf("%d\n", i);
	int ans = ans_p.size();
	printf("%d\n", ans);
	rep(i, ans) printf("%d %d\n", ans_p[i].first, ans_p[i].second);
	return 0;
}


// Author: bill125

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <bitset>
#include <cmath>
#include <stack>

using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> Pair;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repD(i, n) for (int i = n - 1; i >= 0; --i)
#define For(i, a, b) for (int i = a; i <= b; ++i)
#define ForD(i, a, b) for (int i = a; i >= b; --i)
#define ForE(i, a) for (Edge* i = h[a]; i; i = i->next)
#define forv(i, a) for (unsigned int i = 0, ___t = a.size(); i < ___t; ++i)
#define ForV(i, a) for (__typeof(a.begin()) i = a.begin();i != a.end(); ++i)
#define fill(a, b) memset(a, b, sizeof(a))
#define lowbit(a) ((a) & (-(a)))
#define sqr(a) ((a)*(a))
#define pb push_back
#define mp make_pair
#define gi gI()
#define cut puts("===================")

void setIO(string NAME) {
	#ifndef ONLINE_JUDGE
	string in=NAME+".in", out=NAME+".out";freopen(in.c_str(),"r",stdin),freopen(out.c_str(),"w",stdout);
	#endif
}
inline ll gI() {char c=getchar();while ((c<'0' || c>'9')&&c!='-') c=getchar();ll flag=1,p=0;if (c=='-') flag=-1,c=getchar();while (c>='0' && c<='9') p=p*10+(c-'0'),c=getchar();return p*flag;}
int gs(char *C) {char c=getchar();while (c==' ' || c=='\n') c=getchar();int l=0;while (c!=' ' && c!='\n' && c!=EOF) C[l++]=c,c=getchar();C[l]=0;return l;}
template <class T> void debug (const T a,const int & n) {rep(i,n) printf("%d%c", a[i],(i==n-1)?'\n':' ');}

const int inf = ~0U>>1, maxn = 1000000 + 10;
int n, pcnt = 0;
int prime[maxn];
bool vis[maxn];
vector<pair<int, int> >ans_p;

int main() {
	setIO("test");

	n = gi;

	for (int i = 2; i <= n; ++ i) if (!vis[i]) {
		for (int j = i << 1; j <= n; j += i) vis[j] = 1;
		prime[pcnt ++] = i;
	}
	fill(vis, 0);
	int j = 0;
	while (j < pcnt && prime[j] * prime[j] <= n) ++ j;
	For(i, 2, pcnt) {
		if (prime[i] * 2 > n) break;
		repD(k, j) {
			if (prime[i] * prime[k] <= n && !vis[prime[i] * prime[k]]) {
				vis[prime[i] * prime[k]] = 1;
				vis[prime[i]] = 1;
				ans_p.pb(mp(prime[i], prime[i] * prime[i] * prime[k]));
				break;
			}
		}
	}

	int last = -1;
	rep(i, pcnt) {
		last = -1;
		for (int j = prime[i]; j <= n; j += prime[i]) {
			if (!vis[j]) {
				if (last == -1) last = j;
				else {
					ans_p.push_back(make_pair(last, j));
					vis[j] = vis[last] = 1;
					last = -1;
				}
			}
		}
	}
	//For(i, 1, n) if (!vis[i]) printf("%d\n", i);
	int ans = ans_p.size();
	printf("%d\n", ans);
	rep(i, ans) printf("%d %d\n", ans_p[i].first, ans_p[i].second);
	return 0;
}


// Author: bill125

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <bitset>
#include <cmath>
#include <stack>

using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> Pair;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repD(i, n) for (int i = n - 1; i >= 0; --i)
#define For(i, a, b) for (int i = a; i <= b; ++i)
#define ForD(i, a, b) for (int i = a; i >= b; --i)
#define ForE(i, a) for (Edge* i = h[a]; i; i = i->next)
#define forv(i, a) for (unsigned int i = 0, ___t = a.size(); i < ___t; ++i)
#define ForV(i, a) for (__typeof(a.begin()) i = a.begin();i != a.end(); ++i)
#define fill(a, b) memset(a, b, sizeof(a))
#define lowbit(a) ((a) & (-(a)))
#define sqr(a) ((a)*(a))
#define pb push_back
#define mp make_pair
#define gi gI()
#define cut puts("===================")

void setIO(string NAME) {
	#ifndef ONLINE_JUDGE
	string in=NAME+".in", out=NAME+".out";freopen(in.c_str(),"r",stdin),freopen(out.c_str(),"w",stdout);
	#endif
}
inline ll gI() {char c=getchar();while ((c<'0' || c>'9')&&c!='-') c=getchar();ll flag=1,p=0;if (c=='-') flag=-1,c=getchar();while (c>='0' && c<='9') p=p*10+(c-'0'),c=getchar();return p*flag;}
int gs(char *C) {char c=getchar();while (c==' ' || c=='\n') c=getchar();int l=0;while (c!=' ' && c!='\n' && c!=EOF) C[l++]=c,c=getchar();C[l]=0;return l;}
template <class T> void debug (const T a,const int & n) {rep(i,n) printf("%d%c", a[i],(i==n-1)?'\n':' ');}

const int inf = ~0U>>1, maxn = 1000000 + 10;
int n, pcnt = 0;
int prime[maxn];
bool vis[maxn];
vector<pair<int, int> >ans_p;

int main() {
	setIO("test");

	n = gi;

	for (int i = 2; i <= n; ++ i) if (!vis[i]) {
		for (int j = i << 1; j <= n; j += i) vis[j] = 1;
		prime[pcnt ++] = i;
	}
	fill(vis, 0);
	int j = 0;
	while (j < pcnt && prime[j] * prime[j] <= n) ++ j;
	For(i, 2, pcnt) {
		if (prime[i] * 2 > n) break;
		repD(k, j) {
			if (prime[i] * prime[k] <= n && !vis[prime[i] * prime[k]]) {
				vis[prime[i] * prime[k]] = 1;
				vis[prime[i]] = 1;
				ans_p.pb(mp(prime[i], prime[i] * prime[k]));
				break;
			}
		}
	}

	//printf("%d\n", ans_p.size());

	int last = -1;
	rep(i, pcnt) {
		last = -1;
		for (int j = prime[i]; j <= n; j += prime[i]) {
			if (!vis[j]) {
				if (last == -1) last = j;
				else {
					ans_p.push_back(make_pair(last, j));
					vis[j] = vis[last] = 1;
					last = -1;
				}
			}
		}
	}
	//For(i, 1, n) if (!vis[i]) printf("%d\n", i);
	int ans = ans_p.size();
	printf("%d\n", ans);
	rep(i, ans) printf("%d %d\n", ans_p[i].first, ans_p[i].second);
	return 0;
}


// Author: bill125

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <bitset>
#include <cmath>
#include <stack>

using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> Pair;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repD(i, n) for (int i = n - 1; i >= 0; --i)
#define For(i, a, b) for (int i = a; i <= b; ++i)
#define ForD(i, a, b) for (int i = a; i >= b; --i)
#define ForE(i, a) for (Edge* i = h[a]; i; i = i->next)
#define forv(i, a) for (unsigned int i = 0, ___t = a.size(); i < ___t; ++i)
#define ForV(i, a) for (__typeof(a.begin()) i = a.begin();i != a.end(); ++i)
#define fill(a, b) memset(a, b, sizeof(a))
#define lowbit(a) ((a) & (-(a)))
#define sqr(a) ((a)*(a))
#define pb push_back
#define mp make_pair
#define gi gI()
#define cut puts("===================")

void setIO(string NAME) {
    #ifndef ONLINE_JUDGE
    string in=NAME+".in", out=NAME+".out";freopen(in.c_str(),"r",stdin),freopen(out.c_str(),"w",stdout);
    #endif
}
inline ll gI() {char c=getchar();while ((c<'0' || c>'9')&&c!='-') c=getchar();ll flag=1,p=0;if (c=='-') flag=-1,c=getchar();while (c>='0' && c<='9') p=p*10+(c-'0'),c=getchar();return p*flag;}
int gs(char *C) {char c=getchar();while (c==' ' || c=='\n') c=getchar();int l=0;while (c!=' ' && c!='\n' && c!=EOF) C[l++]=c,c=getchar();C[l]=0;return l;}
template <class T> void debug (const T a,const int & n) {rep(i,n) printf("%d%c", a[i],(i==n-1)?'\n':' ');}

const int inf = ~0U>>1, maxn = 1000000 + 10;
int n, pcnt = 0;
int prime[maxn];
bool vis[maxn];
vector<pair<int, int> >ans;

int main() {
    setIO("test");

    n = gi;
    For(i, 2, n) if (!vis[i]) {
        prime[pcnt ++] = i;
        for (int j = i; j <= n; j += i) vis[j] = 1;
    }

    fill(vis, 0);

    repD(i, pcnt) {
        int cnt = 0;
        for (int j = prime[i]; j <= n; j += prime[i])
            cnt += !vis[j];

        if (cnt & 1) {
            For(j, 2, n) {
                if (j * prime[i] > n) break;
                if (!vis[j] && !vis[j * prime[i]]) {
                    vis[j] = vis[j * prime[i]] = 1;
                    ans.push_back(make_pair(j, j * prime[i]));
                }
            }
        }
        int last = -1;
        for (int j = prime[i]; j <= n; j += prime[i]) if (!vis[j]) {
            if (last == -1) last = j;
            else {
                ans.push_back(make_pair(last, j));
                vis[j] = vis[last] = 1;
                last = -1;
            }
        }
    }

    //int ans = ans_p.size();
    printf("%d\n", ans.size());
    forv(i, ans) printf("%d %d\n", ans[i].first, ans[i].second);
    return 0;
}


#include <cstdio>
#include <cassert>

using namespace std;

bool use[100005];
bool pr[100005];
int left[100005];
int right[100005];

int main()
{
	int n;
	scanf("%d",&n);
	int sz=0;
	for(int i=2;i<=n;i++)
	{
		if(!pr[i])
		{
			for(int j=i*2;j<=n;j+=i) pr[j]=true;
		}
	}
	for(int i=n/2;i>=2;i--)
	{
		if(!pr[i])
		{
			int cnt=0;
			for(int j=i;j<=n;j+=i)
			{
				if(!use[i])
				{
					cnt++;
				}
			}
			if(i!=2) assert(cnt>1);
			if(cnt%2==0)
			{
				int bef=-1;
				for(int j=i;j<=n;j+=i)
				{
					if(!use[j])
					{
						use[j]=true;
						if(bef==-1) bef=j;
						else
						{
							left[sz]=bef;
							right[sz]=j;
							bef=-1;
							sz++;
						}
					}
				}
			}
			else
			{
				int bef=i;
				use[i]=true;
				for(int j=i*(i==2?2:3);j<=n;j+=i)
				{
					if(!use[j])
					{
						use[j]=true;
						if(bef==-1) bef=j;
						else
						{
							left[sz]=bef;
							right[sz]=j;
							bef=-1;
							sz++;
						}
					}
				}
			}
		}
	}
	printf("%d\n",sz);
	for(int i=0;i<sz;i++) printf("%d %d\n",left[i],right[i]);
	return 0;
}


#include <cstdio>
#include <cassert>

using namespace std;

bool use[100005];
bool pr[100005];
int left[100005];
int right[100005];

int main()
{
	int n;
	scanf("%d",&n);
	int sz=0;
	for(int i=2;i<=n;i++)
	{
		if(!pr[i])
		{
			for(int j=i*2;j<=n;j+=i) pr[j]=true;
		}
	}
	//int all=n;
	//for(int i=n/2+1;i<=n;i++) if(!pr[i]) all--;
	//printf("%d\n",all/2);
	for(int i=n/2;i>=2;i--)
	{
		if(!pr[i])
		{
			int cnt=0;
			for(int j=i;j<=n;j+=i)
			{
				if(!use[j])
				{
					cnt++;
				}
			}
			//if(i!=2) assert(cnt>1);
			if(cnt%2==0)
			{
				int bef=-1;
				for(int j=i;j<=n;j+=i)
				{
					if(!use[j])
					{
						use[j]=true;
						if(bef==-1) bef=j;
						else
						{
							left[sz]=bef;
							right[sz]=j;
							bef=-1;
							sz++;
						}
					}
				}
			}
			else
			{
				int bef=i;
				use[i]=true;
				for(int j=i*(i==2?2:3);j<=n;j+=i)
				{
					if(!use[j])
					{
						use[j]=true;
						if(bef==-1) bef=j;
						else
						{
							left[sz]=bef;
							right[sz]=j;
							bef=-1;
							sz++;
						}
					}
				}
				//if(bef!=-1) printf("%d\n",bef);
			}
		}
	}
	printf("%d\n",sz);
	for(int i=0;i<sz;i++) printf("%d %d\n",left[i],right[i]);
	//int cnt=0;
	//for(int i=2;i<=n;i++) if(!use[i]&&!(i>=n/2+1&&!pr[i])) printf("%d\n",i);
	//for(int i=2;i<=n;i++) if(use[i]) cnt++;
	//printf("%d\n",cnt/2);
	return 0;
}


#include <cstdio>

using namespace std;

bool use[100005];
bool pr[100005];
int left[100005];
int right[100005];

int main()
{
	int n;
	scanf("%d",&n);
	int sz=0;
	for(int i=2;i<=n;i++)
	{
		if(!pr[i])
		{
			for(int j=i*2;j<=n;j+=i) pr[j]=true;
		}
	}
	for(int i=n/2;i>=2;i--)
	{
		if(!pr[i])
		{
			int cnt=0;
			for(int j=i;j<=n;j+=i)
			{
				if(!use[i])
				{
					cnt++;
				}
			}
			if(cnt%2==0)
			{
				int bef=-1;
				for(int j=i;j<=n;j+=i)
				{
					if(!use[j])
					{
						use[j]=true;
						if(bef==-1) bef=j;
						else
						{
							left[sz]=bef;
							right[sz]=j;
							bef=-1;
							sz++;
						}
					}
				}
			}
			else
			{
				int bef=i;
				use[i]=true;
				for(int j=i*(i==2?2:3);j<=n;j+=i)
				{
					if(!use[j])
					{
						use[j]=true;
						if(bef==-1) bef=j;
						else
						{
							left[sz]=bef;
							right[sz]=j;
							bef=-1;
							sz++;
						}
					}
				}
			}
		}
	}
	printf("%d\n",sz);
	for(int i=0;i<sz;i++) printf("%d %d\n",left[i],right[i]);
	return 0;
}


#include <bits/stdc++.h>
//
using namespace std;
//
#define REP(n,i) for(int (i)=0;(i)<(n);(i)++)
#define CDREP(n,i) for(int (i)=((n)-1);(i)>=0;(i)--)
#define CDFOR(s,e,i) for(int i=((e)-1);(i)>=(s);(i)--)
#define _SZ(n) memset((n),0,sizeof(n))
#define _SMO(n) memset((n),-1,sizeof(n))
#define _MC(n,m) memcpy((n),(m),sizeof(n))
#define _F first
#define _S second
#define _MP(a,b) make_pair((a),(b))
#define _PB(a) push_back((a))
#define FOR(x,y) for(__typeof(y.begin())x=y.begin();x!=y.end();x++)
#define IOS ios_base::sync_with_stdio(0);
// Let's Fight!

const int MAXN = 101010;

int N;
bool notp[MAXN];
bool used[MAXN];

int cnt = 0;
int arr[MAXN];

void init()
{
    notp[0] = notp[1] = true;
    for(int i=2; i<=N; i++)
    {
        if(notp[i])
            continue;
        for(int j=2*i; j<=N; j+=i)
        {
            notp[j] = true;
        }
    }
}

int main()
{
    scanf("%d", &N);
    init();

    for(int i=N; i>=2; i--)
    {
        if(notp[i])continue;
        if(i*2>N)continue;
        int c = 0;
        for(int j=i; j<=N; j+=i)
        {
            if(j==2*i)continue;
            if(used[j])continue;
            used[j] = true;
            c++;
            arr[cnt] = j;
            cnt++;
        }
        if(c%2)
        {
            used[i*2] = true;
            c++;
            arr[cnt] = i*2;
            cnt++;
        }
    }

    int m = cnt/2;
    printf("%d\n", m);

    for(int i=0; i<m; i++)
    {
        printf("%d %d\n", arr[2*i], arr[2*i+1]);
    }

	return 0;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stdio.h>
#include <ctime>
#include <cstdlib>
#include <utility>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>

#define inf (999999999)
#define pii pair<int,int>
#define pip pair<int,pii>
#define pll pair<long long,long long>
#define eps 1e-8

#ifdef ONLINE_JUDGE
#define debug(args...)
#else
#define debug(args...) fprintf(stderr,args)
#endif

#define pb push_back

using namespace std;

int foi[100100];

int primo(int a){
	for(int i=2;i*i<=a;i++)
		if(a%i == 0) return 0;
	return 1;
}

main(){

		int n;
		scanf("%d",&n);

		vector<pii> ans;

		for(int i=n;i>=2;i--) if(primo(i)) {

			vector<int> v;

			for(int j=1;i*j<=n;j++)
				if(!foi[i*j]) v.pb(i*j);

			if(v.size() == 1) continue;

			if(v.size()%2 == 1){

				swap(v[0],v[1]);
				reverse(v.begin(), v.end());
				v.pop_back();

			}

			for(int j=0;j<v.size();j+=2)
				ans.pb(pii(v[j],v[j+1])), foi[v[j]] = foi[v[j+1]] = 1;

		}

		printf("%d\n",ans.size());

		for(int i=0;i<ans.size();i++)
			printf("%d %d\n",ans[i].first,ans[i].second);

}


#include<bits/stdc++.h>
using namespace std;
main(){

    int n;
    scanf("%d",&n);
    vector<pair<int,int> > ans;
    vector<int> v;
    vector<char> flag(n+1);

    for(int i=3;i<=n/2;i++){
        if(flag[i]) continue;
        vector<int> tmp;
        for(int j=i;j<=n;j+=i)
            if(!flag[j]) tmp.push_back(j);
        if(tmp.size()==1) continue;
        if(tmp.size()&1){
            //v.push_back(tmp[1]);
            swap(tmp[1],tmp.back());
        }
        for(int j=0;j+1<tmp.size();j+=2){
            int x,y;
            x=tmp[j];
            y=tmp[j+1];
            flag[x]=flag[y]=true;
            ans.push_back(make_pair(x,y));
        }
    }

    for(int i=2;i<=n;i+=2)
        if(!flag[i]) v.push_back(i);
    for(int i=0;i+1<v.size();i+=2) ans.push_back(make_pair(v[i],v[i+1]));
    printf("%d\n",ans.size());
    for(int i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);

    return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
#define LL long long
#define maxn 100005
int prime[maxn], size, anssize; bool bo[maxn];
pair<int, int> arr[maxn];
void genprime(int n){
	for (LL i = 2; i <= n; i++) if (!bo[i]) for (LL j = i * i; j <= n; j += i) bo[j] = true;
	for (int i = 2; i <= n; i++) if (!bo[i]) prime[size++] = i;
}
int main(){
	int n, j, num, las;
	cin >> n;
	genprime(n / 2); memset(bo, 0, sizeof bo);
	for (int i = size - 1; i >= 0; i--){
		for (j = prime[i] * 3, num = 0, las = 0; j <= n; j += prime[i]) if (!bo[j]){
			num++; if (num == 2) bo[j] = bo[las] = true, arr[anssize].first = j, arr[anssize++].second = las, num = 0; else las = j;
		}
		if (num == 1) bo[las] = bo[prime[i]] = true, arr[anssize].first = las, arr[anssize ++].second = prime[i];
		else if (!bo[prime[i] * 2]) bo[prime[i]] = bo[prime[i] * 2] = true, arr[anssize].first = prime[i], arr[anssize++].second = prime[i] * 2;
	}
	cout << anssize << endl;
	for (int i = 0; i < anssize; i++) cout << arr[i].first << ' ' << arr[i].second << endl;
//	system("PAUSE");
	return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
#define maxn 100005
int prime[maxn], size, anssize; bool bo[maxn];
pair<int, int> arr[maxn];
void genprime(int n){
	for (int i = 2; i <= n; i++) if (!bo[i]) for (int j = i * i; j <= n; j += i) bo[j] = true;
	for (int i = 2; i <= n; i++) if (!bo[i]) prime[size++] = i;
}
int main(){
	int n;
	cin >> n;
	genprime(n); memset(bo, 0, sizeof bo);
	for (int i = 0; i <= size - 1; i++) for (int j = prime[i], num = 0, las = 0; j <= n; j += prime[i]) if (!bo[j]){
		num++; if (num == 2) bo[j] = bo[las] = true, arr[anssize].first = j, arr[anssize ++].second = las, num = 0; else las = j;
	}
	cout << anssize << endl;
	for (int i = 0; i < anssize; i++) cout << arr[i].first << ' ' << arr[i].second << endl;
//	system("PAUSE");
	return 0;
}


#include <iostream>
using namespace std;
#define maxn 100005
int prime[maxn], size, anssize; bool bo[maxn];
pair<int, int> arr[maxn];
void genprime(int n){
    for (int i = 2; i <= n; i++) if (!bo[i]) for (int j = i * i; j <= n; j += i) bo[j] = true;
    for (int i = 2; i <= n; i++) if (!bo[i]) prime[size++] = i;
}
int main(){
    int n;
    cin >> n;
    genprime(n); memset(bo, 0, sizeof bo);
    for (int i = 0; i <= size - 1; i++) for (int j = prime[i], num = 0, las = 0; j <= n; j += prime[i]) if (!bo[j]){
        num++; if (num == 2) bo[j] = bo[las] = true, arr[anssize].first = j, arr[anssize ++].second = las, num = 0; else las = j;
    }
    cout << anssize << endl;
    for (int i = 0; i < anssize; i++) cout << arr[i].first << ' ' << arr[i].second << endl;
//  system("PAUSE");
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MAXN 50000

int A[MAXN + 1], p[MAXN + 1], pc = 0;

void sieve()
{
    for(int i=2; i<=MAXN; i++){
        if(!A[i]) p[A[i] = ++pc] = i;
        for(int j=1; j<=A[i] && i*p[j]<=MAXN; j++)
            A[i*p[j]] = j;
    }
}

void add(vector < pair <int, int> > &G, vector <int> &v)
{
    for(int i=0; i+1<v.size(); i+=2)
        G.push_back(make_pair(v[i], v[i+1]));
}

bool used[MAXN * 2 + 1];

int main()
{
    sieve();

    int n;
    while(scanf("%d", &n) == 1)
    {
        memset(used, 0, sizeof(used));

        vector < pair <int, int> > G;
        vector <int> u;
        for(int i=2; i<=pc; i++)
        {
            if(2 * p[i] <= n)
            {
                vector <int> v;

                int x = p[i];
                while(x <= n)
                {
                    if(x != 2 * p[i] && !used[x])
                    {
                        used[x] = 1;
                        v.push_back(x);
                    }
                    x += p[i];
                }

                used[2 * p[i]] = 1;
                if(v.size() % 2 == 1) v.push_back(2 * p[i]);
                else u.push_back(2 * p[i]);

                add(G, v);
            }
        }

        for(int i=2; i<=n; i+=2)
            if(!used[i])
                u.push_back(i);
        add(G, u);

        printf("%d\n", (int)G.size());
        for(int i=0; i<G.size(); i++)
            printf("%d %d\n", G[i].first, G[i].second);
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MAXN 50000

int A[MAXN + 1], p[MAXN + 1], pc = 0;

void sieve()
{
    for(int i=2; i<=MAXN; i++){
        if(!A[i]) p[A[i] = ++pc] = i;
        for(int j=1; j<=A[i] && i*p[j]<=MAXN; j++)
            A[i*p[j]] = j;
    }
}

void add(vector < pair <int, int> > &G, vector <int> &v)
{
    for(int i=0; i+1<v.size(); i+=2)
        G.push_back(make_pair(v[i], v[i+1]));
}

bool used[MAXN * 2 + 1];

int main()
{
    sieve();

    int n;
    while(cin>>n)
    {
        memset(used, 0, sizeof(used));

        vector < pair <int, int> > G;
        vector <int> u;
        for(int i=2; i<=pc; i++)
        {
            if(2 * p[i] <= n)
            {
                vector <int> v;

                int x = p[i];
                while(x <= n)
                {
                    if(x != 2 * p[i] && !used[x])
                    {
                        used[x] = 1;
                        v.push_back(x);
                    }
                    x += p[i];
                }

                used[2 * p[i]] = 1;
                if(v.size() % 2 == 1) v.push_back(2 * p[i]);
                else u.push_back(2 * p[i]);

                add(G, v);
            }
        }

        for(int i=2; i<=n; i+=2)
            if(!used[i])
                u.push_back(i);
        add(G, u);

        cout<<G.size()<<endl;
        for(int i=0; i<G.size(); i++)
            cout<<G[i].first<<" "<<G[i].second<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MAXN 50000

int A[MAXN + 1], p[MAXN + 1], pc = 0;

void sieve()
{
    for(int i=2; i<=MAXN; i++){
        if(!A[i]) p[A[i] = ++pc] = i;
        for(int j=1; j<=A[i] && i*p[j]<=MAXN; j++)
            A[i*p[j]] = j;
    }
}

void add(vector < pair <int, int> > &G, vector <int> &v)
{
    for(int i=0; i+1<v.size(); i++)
        G.push_back(make_pair(v[i], v[i+1]));
}

bool used[MAXN * 2 + 1];

int main()
{
    sieve();

    int n;
    while(cin>>n)
    {
        memset(used, 0, sizeof(used));

        vector < pair <int, int> > G;
        vector <int> u;
        for(int i=2; i<=pc; i++)
        {
            if(2 * p[i] <= n)
            {
                vector <int> v;

                int x = p[i];
                while(x <= n)
                {
                    if(x != 2 * p[i] && !used[x])
                    {
                        used[x] = 1;
                        v.push_back(x);
                    }
                    x += p[i];
                }

                used[2 * p[i]] = 1;
                if(v.size() % 2 == 1) v.push_back(2 * p[i]);
                else u.push_back(2 * p[i]);

                add(G, v);
            }
        }
        for(int i=2; i<=n; i+=2)
            if(!used[i])
                u.push_back(i);
        add(G, u);

        cout<<G.size()<<endl;
        for(int i=0; i<G.size(); i++)
            cout<<G[i].first<<" "<<G[i].second<<endl;
    }

    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
//#include <memory>
//#include <thread>
using namespace std;

#define INF 1e+9
#define mp make_pair
#define lint long long
#define pii pair<int, int>
#define MAXN 1000000

int mind[MAXN];
int kol[MAXN];
vector<int> md[MAXN];
int pr[MAXN];

int main() {
    ios_base::sync_with_stdio(false);
    int n; cin >> n;
    fill(mind, mind + n + 1, 1e+9);
    memset(pr, -1, sizeof pr);
    mind[1] = 1;
    for (int i = 2; i <= n; i++) {
        mind[i] = min(mind[i], i);
        for (int j = i; j <= n; j += i) {
            mind[j] = min(mind[j], mind[i]);
        }
    }
    for (int i = 1; i <= n; i++)
        md[mind[i]].push_back(i);
    int pq = -1;
    for (int i = 2; 2 * i <= n; i++) {
        if (md[i].size() % 2 == 1) {
            if (pq == -1) pq = i;
            else {
                pr[i] = 2 * i;
                pr[2 * i] = i;
                pr[pq] = 2 * pq;
                pr[2 * pq] = pq;
                pq = -1;
            }
        }
    }
    for (int i = 2; i <= n; i++) {
        int pq = -1;
        for (int j = md[i].size()%2; j < md[i].size(); j++) {
            if (pr[md[i][j]] == -1) {
                if (pq == -1) pq = md[i][j];
                else {
                    int cc = md[i][j];
                    pr[cc] = pq;
                    pr[pq] = cc;
                    pq = -1;
                }
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (pr[i] > i) {
            ans++;
        }
    }
    cout << ans << endl;
    for (int i = 1; i <= n; i++)
        if (pr[i] > i) {
            cout << i << " " << pr[i] << endl;
        }
}


#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>

using namespace std;

bool notPrime[100001], matched[100001];
int n;

int main(void)
{
	notPrime[0] = notPrime[1] = true;
	for(int i = 2; i < 100000; i++)
	{
		if(notPrime[i]) continue;
		for(int j = i * 2; j < 100000; j += i)
			notPrime[j] = true;
	}

	int n;
	scanf("%d", &n);

	vector <pair<int, int>> ans;
	vector <int> outs;
	for(int i = n / 2; i >= 2; i--)
	{
		if(notPrime[i]) continue;
		vector <int> cur;
		for(int j = i; j <= n; j += i)
		{
			if(matched[j] == false)
				cur.push_back(j);
			matched[j] = true;
		}

		if(cur.size() % 2 == 0)
		{
			for(int j = 0; j < cur.size(); j += 2) ans.push_back(make_pair(cur[j], cur[j + 1]));
		}
		else
		{
			if(cur.size() > 2)
			{
				ans.push_back(make_pair(cur[0], cur[2]));
				outs.push_back(cur[1]);
			}
			for(int j = 3; j < cur.size(); j += 2) ans.push_back(make_pair(cur[j], cur[j + 1]));
		}
	}

	for(int i = 1; i < outs.size(); i += 2) ans.push_back(make_pair(outs[i - 1], outs[i]));
	printf("%d\n", (int)ans.size());
	for(auto v: ans) printf("%d %d\n", v.first, v.second);

	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for(int _b=(b),i=(a); i<_b; ++i)
#define ROF(i,b,a) for(int _a=(a),i=(b); i>_a; --i)
#define PB(x) push_back(x)
#define _1 first
#define _2 second
#define MP(x,y) make_pair(x,y)
#define MSET(m,v) memset(m,v,sizeof(m))
#define MAX_PQ(T) priority_queue <T>
#define MIN_PQ(T) priority_queue <T,vector<T>,greater<T>>
#define clear_cont(cont)    {while(!cont.empty()) cont.pop();}

typedef long long LL; typedef unsigned long long ULL; typedef long double LD;
typedef pair<int,int> PII; typedef pair<LL,LL> PLL;
typedef vector<int> VI; typedef vector<LL> VL; typedef vector<PII> VP;
template<typename A, typename B> inline void mina(A &x, B y) { if(x > y) x = y; }
template<typename A, typename B> inline void maxa(A &x, B y) { if(x < y) x = y; }

//------------------//
  #define DEBUG_ON
//------------------//

#ifdef DEBUG_ON // requires C++11 for "auto" types
template<class T1, class T2>
ostream& operator << (ostream &out, pair<T1, T2> P)
{return out << "(" << P.first << ", " << P.second << ")";}
template <class T> void _spn_print_cont_for(T const& C)
{int first = 1; cout << "["; for(auto a: C) {if(!first) printf(", "); first = 0; cout << a;} cout << "]" << endl;}
template <class T> void _spn_print_vector_lr(vector <T> const& C, int l, int r)
{if(l < 0 || r >= C.size()) {printf("ARRAY OUT OF BOUND [0,%d]\n\n", (int)C.size()-1); return;} int first = 1; cout << "[";
for(int i=l; i<=r; ++i) {if(!first) printf(", "); first = 0; cout << C[i];} cout << "]" << endl;}
#define print_value(label, datum)      (cout << (label) << " : " << (datum) << endl)
#define print_var(var)                 (cout << #var << " : " << (var) << endl)
#define print_cont_list(cont, top)     {auto _C_ = cont; cout << #cont << " :"; while(!_C_.empty()) {cout << " " << _C_.top(); _C_.pop();} cout << endl;}
#define print_cont_for(cont)           {cout << #cont << " : "; _spn_print_cont_for(cont);}
#define print_vector_lr(vt, l, r)      {printf(#vt " [%d,%d] : ", int(l), int(r)); _spn_print_vector_lr((vt), (l), (r));}
#define clear_cont_print(cont, top)    {cout << #cont << ":"; while(!cont.empty()) {cout << " " << cont.top(); cont.pop();} cout << endl;}
#else // DEBUG_ON
#define print_value(label, datum)
#define print_var(var)
#define print_cont_list(cont, top)
#define print_cont_for(vt)
#define print_vector_lr(vt, l, r)
#define clear_cont_print(cont, top)    clear_cont(cont)
#endif // DEBUG_ON

// More templates here

#define MAXN (100005)

int N;
int S[MAXN];
int V[MAXN];

int main()
{
	scanf("%d", &N);

	S[0] = S[1] = 1;
	FOR(i,2,N+1)
	{
		if(S[i]) continue;

//		printf("%d ", i);

		if(LL(i) * i > N) continue;
		for(int j = i * i; j <= N; j += i)
			S[j] = 1;
	}
//	putchar('\n');

	VP sol;

	ROF(i,N,1)
	{
		if(S[i]) continue;

		int l2 = 0;
		int l = 0;
		for(int j = i; j <= N; j += i)
		{
			if(V[j]) continue;

			if(!l2 && (j&1) == 0) l2 = j;
			else
			{
				if(!l) l = j;
				else
				{
					sol.PB(PII(l, j));
					V[l] = V[j] = 1;
					l = 0;
				}
			}
		}

		if(l && l2)
		{
			sol.PB(PII(l, l2));
			V[l] = V[l2] = 1;
		}
	}

	printf("%d\n", int(sol.size()));
	for(PII p : sol)
		printf("%d %d\n", p._1, p._2);

	return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <utility>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define PB push_back
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#ifdef LOCAL
#define debug(x) {cerr <<#x <<" = " <<x <<"\n"; }
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(x)
#define debugv(x)
#endif
#define make(type, x) type x; cin>>x;
#define make2(type, x, y) type x, y; cin>>x>>y;
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
using namespace std;
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
const int N = 1e5 + 5;
vector<int> nums[N];
int sieve[N];
int pres[N];
int main() {
  // nie zapomnij o ll
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  double beg = 1.0 * clock() / CLOCKS_PER_SEC;

  make(int, n);
  VPII res;
  for (int i = 2; i <= n; i++) {
    if (sieve[i] == 0) {
      for (int j = 1; i * j <= n; j++) {
        if (sieve[i * j] == 0) {
          nums[i].PB(i * j);
          sieve[i * j] = i;
        }
      }
    }
  }
  for (int d = n; d >= 3; d--) {
    while (nums[d].size() >= 2) {
      res.PB(MP(nums[d].back(), nums[d][nums[d].size() - 2]));
      nums[d].pop_back();
      nums[d].pop_back();
    }
    if (nums[d].size()) {
      if (nums[d][0] * 2 <= n) {
        res.PB(MP(nums[d][0], 2 * nums[d][0]));
        pres[2 * nums[d][0]] = 1;
      }
    }
  }
  vector<int> rest;
  for (auto a : nums[2]) {
    if (!pres[a]) {
      rest.PB(a);
    }
  }
  while (rest.size() >= 2) {
    res.PB(MP(rest.back(), rest[rest.size() - 2]));
    rest.pop_back();
    rest.pop_back();
  }
  cout<<res.size()<<endl;
  for (auto p : res) {
    cout<<p.first<<" "<<p.second<<"\n";
  }

  // nie zapomnij o ll
  return 0;
}


#include <bits/stdc++.h>

/*** TEMPLATE CODE STARTS HERE ***/

using namespace std;

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef complex<double> pnt;
typedef pair<int, int> pii;

#define RA(x) begin(x), end(x)
#define FE(i, x) for (auto i = begin(x); i != end(x); ++i)
#define SZ(x) ((int) (x).size())

template<class T>
void splitstr(const string &s, vector<T> &out)
{
    istringstream in(s);
    out.clear();
    copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

static void redirect(int argc, const char **argv)
{
    ios::sync_with_stdio(false);
    if (argc > 1)
    {
        static filebuf f;
        f.open(argv[1], ios::in);
        cin.rdbuf(&f);
        if (!cin)
        {
            cerr << "Failed to open '" << argv[1] << "'" << endl;
            exit(1);
        }
    }

    if (argc > 2)
    {
        static filebuf f;
        f.open(argv[2], ios::out | ios::trunc);
        cout.rdbuf(&f);
        if (!cout)
        {
            cerr << "Failed to open '" << argv[2] << "'" << endl;
        }
    }
}

/*** TEMPLATE CODE ENDS HERE */

static vector<int> primes;

static void make_primes(int N)
{
    vector<bool> comp(N + 1);
    for (int i = 2; i <= N; i++)
        if (!comp[i])
        {
            for (int j = i * 2; j <= N; j += i)
                comp[j] = true;
            primes.push_back(i);
        }
}

int main(int argc, const char **argv)
{
    redirect(argc, argv);

    int N;
    cin >> N;
    make_primes(N);
    reverse(RA(primes));
    vector<bool> used(N + 1);
    vector<pii> ans;
    for (int p : primes)
    {
        if (2 * p > N)
            continue;

        int have = 0;
        bool save = false;
        for (int i = p; i <= N; i += p)
            if (!used[i])
                have++;
        if ((have & 1) && (p != 2))
            save = true;
        if (save)
        {
            assert(!used[2 * p]);
            used[2 * p] = true;
            have--;
        }

        int last = -1;
        for (int i = p; i <= N; i += p)
            if (!used[i])
            {
                used[i] = true;
                if (last == -1)
                    last = i;
                else
                {
                    ans.emplace_back(last, i);
                    last = -1;
                }
            }

        if (save)
            used[2 * p] = false;
    }

    cout << ans.size() << '\n';
    for (const auto &a : ans)
        cout << a.first << ' ' << a.second << '\n';
    return 0;
}