#include "testlib.h"
#include <iostream>

using namespace std;

int rprime(int n)
{   int p[12] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37};
    int k = 1;
    while (n % p[k] == 0) k++;
    return p[k];
}

int main(int argc, char* argv[])
{
    registerGen(argc, argv);
    int n = atoi(argv[1]);
    cout << n << endl;
    int a[n + 1];

    int d = rprime(n);
    int t = rnd.next(1,n-1);    
    for(int i = 1; i <= n; i++)
    {   a[i] = t + 1;  // (t > 0 ? t : n);
        t = (t + d) % n;
    }

    d = rprime(n-1);
    t = rnd.next(1,n-1);
    for(int i = 1; i < n; i++)
    {   cout << a[t+1] << " " << a[t+2] << endl;
        t = (t + d) % (n - 1);
    }

// cout << a[1] << a[2] << a[3] << a[4] << a[5] << a[6] << endl;

    return 0;
}