#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin >> n;
    long long int sum = 0;
    for (long long int i = 1; i <= n; i++)
    {
        for (long long int j = 1; j <= n; j++)
        {
            long long int t;
            t = __gcd(i, j);
            for (long long int k = 1; k <= n; k++)
            {
                sum = sum + __gcd(t, k);
                //cout << sum << " ";
            }
        }
    }
    cout << sum << endl;
}