#include <bits/stdc++.h>
using namespace std;

int kobaisu(int x, int y, int z)
{
    int p = max(x, y);
    int q = min(x, y);
    int n, m;
    while (p % q != 0)
    {
        n = q;
        q = p % q;
        p = n;
    }
    int r = max(q, z);
    int s = min(q, z);
    while (r % s != 0)
    {
        m = s;
        s = r % s;
        r = m;
    }
    return s;
}

int main()
{
    int K;
    cin >> K;
    int64_t count = 0;

    for (int i = 2; i <= K; i++)
    {
        for (int j = 2; j <= K; j++)
        {
            for (int k = 2; k <= K; k++)
            {
                count += kobaisu(i, j, k);
            }
       }
    }

    count += (3 * K * K - 3 * K + 1);
    cout << count;
}