#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long unsigned int ll;

unsigned egcd(unsigned a, unsigned b)
{
    if (a < b)
        return egcd(b, a);
    unsigned r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

int main()
{
    int k;
    cin >> k;
    long long ans = 0;

    for (int i = 1; i < k + 1; i++)
    {
        for (int j = 1; j < k + 1; j++)
        {
            for (int s = 1; s < k + 1; s++)
            {
                ans += __gcd(__gcd(i, j), s);
            }
        }
    }

    cout << ans << endl;
}
