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

int calcGcd(int a, int b, int c)
{
    int x = a, y = b, rem = x % y;
    while (rem != 0)
    {
        x = y;
        y = rem;
        rem = x % y;
    }

    int gcd = y;

    x = gcd;
    y = c;
    rem = x % y;
    while (rem != 0)
    {
        x = y;
        y = rem;
        rem = x % y;
    }

    gcd = y;

    return y;
}

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

    long long gcdSum = 0;

    int maxSum = k * 3;

    for (int a = 1; a <= k; ++a)
    {
        for (int b = 1; b <= k; ++b)
        {
            for (int c = 1; c <= k; ++c)
            {
                gcdSum += calcGcd(a, b, c);
            }
        }
    }

    cout << gcdSum << endl;
}