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

ll maxCommon(ll a, ll b)
{
    ll tmp1,tmp2,r;
        if(a >= b)
        {
            tmp1 = a;
            tmp2 = b;
        }
        else
        {
            tmp1 = a;
            tmp2 = b;
        }

        r = tmp1 % tmp2;

        while(r != 0)
        {
            tmp1 = tmp2;
            tmp2 = r;
            r = tmp1 % tmp2;
        }
    return tmp2;
}

int main()
{
    ll N;
    cin >> N;
    ll sum = 0;

    for(ll i = 1; i <= N; i++)
    {
        for(ll j = 1; j <= N; j++)
        {
            for(ll k = 1; k <= N; k++)
            {
                ll tmp = maxCommon(i,j);
                tmp =  maxCommon(tmp,k);
                sum += tmp;
            }
        }
    }   
    cout << sum << endl;
}