#include <bits/stdc++.h>
int main()
{
    using namespace std;
    int K, a, b, tmp, sum(0);
    cin >> K;
    for (int i = 1; i <= K; i++)
    {
        for (int j = i; j <= K; j++)
        {
            for (int k = j; k <= K; k++)
            {
                if (i == j && j == k)
                {
                    sum += i;
                }
                else
                {
                    a = gcd(i, k);
                    if (i != j && j != k && k != i)
                        sum += a * 6;
                    else
                    {
                        sum += a * 3;
                    }
                }
            }
        }
    }
    cout << sum << endl;
}