#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

ll gcd(ll x, ll y)
{
    if (x == 0)
        return y;

    if (y == 0)
        return x;

    return gcd(y, x % y);
}

int main()
{
    int k;

    cin >> k;

    ll ans = 0;

    for (int a = 1; a <= k; a++)
    {
        for (int b = 1; b <= k; b++)
        {
            for (int c = 1; c <= k; c++)
            {
                ll g = gcd(a, b);
                g = gcd(g, c);

                ans += g;
            }
        }
    }

    cout << ans;

    return 0;
}